forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib_experimental_io.F90
165 lines (135 loc) · 3.2 KB
/
stdlib_experimental_io.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
module stdlib_experimental_io
use iso_fortran_env, only: int8, int16, int32, int64, sp=>real32, dp=>real64, qp=>real128
implicit none
private
public :: loadtxt, savetxt
interface loadtxt
module procedure i8loadtxt
module procedure i16loadtxt
module procedure i32loadtxt
module procedure i64loadtxt
module procedure sloadtxt
module procedure dloadtxt
module procedure qloadtxt
end interface
interface savetxt
module procedure i8loadtxt
module procedure i16loadtxt
module procedure i32loadtxt
module procedure i64loadtxt
module procedure ssavetxt
module procedure dsavetxt
module procedure qsavetxt
end interface
contains
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ i8loadtxt
#define TYPE_ integer(int8)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ i16loadtxt
#define TYPE_ integer(int16)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ i32loadtxt
#define TYPE_ integer(int32)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ i64loadtxt
#define TYPE_ integer(int64)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ sloadtxt
#define TYPE_ real(sp)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ dloadtxt
#define TYPE_ real(dp)
#include "loadtxt.inc"
#undef SUB_LOADTXT_
#undef TYPE_
#define SUB_LOADTXT_ qloadtxt
#define TYPE_ real(qp)
#include "loadtxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ i8savetxt
#define TYPE_ integer(int8)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ i16savetxt
#define TYPE_ integer(int16)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ i32savetxt
#define TYPE_ integer(int32)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ i64savetxt
#define TYPE_ integer(int64)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ ssavetxt
#define TYPE_ real(sp)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ dsavetxt
#define TYPE_ real(dp)
#include "savetxt.inc"
#undef SUB_SAVETXT_
#undef TYPE_
#define SUB_SAVETXT_ qsavetxt
#define TYPE_ real(qp)
#include "savetxt.inc"
integer function number_of_columns(s)
! determine number of columns
integer,intent(in)::s
integer :: ios
character :: c
logical :: lastwhite
rewind(s)
number_of_columns = 0
lastwhite = .true.
do
read(s, '(a)', advance='no', iostat=ios) c
if (ios /= 0) exit
if (lastwhite .and. .not. whitechar(c)) number_of_columns = number_of_columns + 1
lastwhite = whitechar(c)
end do
rewind(s)
end function
integer function number_of_rows_numeric(s)
! determine number or rows
integer,intent(in)::s
integer :: ios
real::r
rewind(s)
number_of_rows_numeric = 0
do
read(s, *, iostat=ios) r
if (ios /= 0) exit
number_of_rows_numeric = number_of_rows_numeric + 1
end do
rewind(s)
end function
logical function whitechar(char) ! white character
! returns .true. if char is space (32) or tab (9), .false. otherwise
character, intent(in) :: char
if (iachar(char) == 32 .or. iachar(char) == 9) then
whitechar = .true.
else
whitechar = .false.
end if
end function
end module