1
1
module stdlib_experimental_io
2
- use iso_fortran_env, only: dp= >real64
2
+ use iso_fortran_env, only: sp = >real32, dp= >real64
3
3
implicit none
4
4
private
5
5
public :: loadtxt, savetxt
6
6
7
+ interface loadtxt
8
+ module procedure sloadtxt
9
+ module procedure dloadtxt
10
+ end interface
11
+
12
+ interface savetxt
13
+ module procedure ssavetxt
14
+ module procedure dsavetxt
15
+ end interface
16
+
7
17
contains
8
18
9
- subroutine loadtxt (filename , d )
19
+ subroutine sloadtxt (filename , d )
20
+ character (len=* ), intent (in ) :: filename
21
+ real (sp), allocatable , intent (out ) :: d(:,:)
22
+ real (dp), allocatable :: tmp(:,:)
23
+ call dloadtxt(filename, tmp)
24
+ allocate (d(size (tmp,1 ),size (tmp,2 )))
25
+ d = real (tmp,sp)
26
+ end subroutine
27
+
28
+ subroutine dloadtxt (filename , d )
10
29
! Loads a 2D array from a text file.
11
30
!
12
31
! Arguments
@@ -15,7 +34,7 @@ subroutine loadtxt(filename, d)
15
34
! Filename to load the array from
16
35
character (len=* ), intent (in ) :: filename
17
36
! The array 'd' will be automatically allocated with the correct dimensions
18
- real (dp), allocatable , intent (out ) :: d(:, :)
37
+ real (dp), allocatable , intent (out ) :: d(:,:)
19
38
!
20
39
! Example
21
40
! -------
@@ -67,14 +86,20 @@ subroutine loadtxt(filename, d)
67
86
close (s)
68
87
end subroutine
69
88
70
- subroutine savetxt (filename , d )
89
+ subroutine ssavetxt (filename , d )
90
+ character (len=* ), intent (in ) :: filename
91
+ real (sp), intent (in ) :: d(:,:)
92
+ call dsavetxt(filename, real (d,dp))
93
+ end subroutine
94
+
95
+ subroutine dsavetxt (filename , d )
71
96
! Saves a 2D array into a textfile.
72
97
!
73
98
! Arguments
74
99
! ---------
75
100
!
76
101
character (len=* ), intent (in ) :: filename ! File to save the array to
77
- real (dp), intent (in ) :: d(:, :) ! The 2D array to save
102
+ real (dp), intent (in ) :: d(:,:) ! The 2D array to save
78
103
!
79
104
! Example
80
105
! -------
0 commit comments