forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_loadtxt.f90
47 lines (36 loc) · 919 Bytes
/
test_loadtxt.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
program test_loadtxt
use iso_fortran_env, only: sp=>real32, dp=>real64
use stdlib_experimental_io, only: loadtxt
use stdlib_experimental_error, only: error_stop
implicit none
real(sp), allocatable :: s(:, :)
real(dp), allocatable :: d(:, :)
call loadtxt("array1.dat", s)
call print_array(s)
call loadtxt("array1.dat", d)
call print_array(d)
call loadtxt("array2.dat", d)
call print_array(d)
call loadtxt("array3.dat", d)
call print_array(d)
call loadtxt("array4.dat", d)
call print_array(d)
contains
subroutine print_array(a)
class(*),intent(in) :: a(:, :)
integer :: i
print *, "Array, shape=(", size(a, 1), ",", size(a, 2), ")"
select type(a)
type is(real(sp))
do i = 1, size(a, 1)
print *, a(i, :)
end do
type is(real(dp))
do i = 1, size(a, 1)
print *, a(i, :)
end do
class default
call error_stop('The proposed type is not supported')
end select
end subroutine
end program