Skip to content

Commit 5e8294c

Browse files
authored
Merge branch 'master' into dev-quadrature
2 parents ccaf548 + 7397e96 commit 5e8294c

23 files changed

+1448
-312
lines changed

STYLE_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This style guide is a living document and proposed changes may be adopted after
2929
By setting and following a convention for indentation and whitespace, code reviews and git-diffs can
3030
focus on the semantics of the proposed changes rather than style and formatting.
3131

32-
* The body of every Fortran construct should be indented by __two (4) spaces__
32+
* The body of every Fortran construct should be indented by __four (4) spaces__
3333
* Line length *should be limited to 80 characters* and __must not exceed 132__
3434
* Please do not use <kbd>Tab</kbd> characters for indentation
3535
* Please remove trailing white space before committing code

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Create a list of the files to be preprocessed
44
set(fppFiles
55
stdlib_experimental_io.fypp
6+
stdlib_experimental_optval.fypp
67
stdlib_experimental_stats.fypp
78
stdlib_experimental_stats_mean.fypp
9+
stdlib_experimental_stats_var.fypp
810
stdlib_experimental_quadrature.fypp
911
stdlib_experimental_quadrature_trapz.fypp
1012
)
@@ -23,10 +25,8 @@ fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
2325

2426
set(SRC
2527
stdlib_experimental_ascii.f90
26-
stdlib_experimental_io.f90
2728
stdlib_experimental_error.f90
2829
stdlib_experimental_kinds.f90
29-
stdlib_experimental_optval.f90
3030
stdlib_experimental_system.F90
3131
${outFiles}
3232
)

src/Makefile.manual

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ SRC = stdlib_experimental_ascii.f90 \
55
stdlib_experimental_kinds.f90 \
66
f18estop.f90 \
77
stdlib_experimental_stats.f90 \
8-
stdlib_experimental_stats_mean.f90
8+
stdlib_experimental_stats_mean.f90 \
9+
stdlib_experimental_stats_var.f90
910

1011
LIB = libstdlib.a
1112

@@ -42,6 +43,11 @@ stdlib_experimental_stats_mean.o: \
4243
stdlib_experimental_optval.o \
4344
stdlib_experimental_kinds.o \
4445
stdlib_experimental_stats.o
46+
stdlib_experimental_stats_var.o: \
47+
stdlib_experimental_optval.o \
48+
stdlib_experimental_kinds.o \
49+
stdlib_experimental_stats.o
4550
stdlib_experimental_io.f90: stdlib_experimental_io.fypp
4651
stdlib_experimental_stats.f90: stdlib_experimental_stats.fypp
4752
stdlib_experimental_stats_mean.f90: stdlib_experimental_stats_mean.fypp
53+
stdlib_experimental_stats_var.f90: stdlib_experimental_stats_var.fypp

src/common.fypp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#! Collected (kind, type) tuples for real types
1010
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES))
1111

12+
#! Complex kinds to be considered during templating
13+
#:set CMPLX_KINDS = ["sp", "dp", "qp"]
14+
15+
#! Complex types to be considere during templating
16+
#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS]
17+
18+
#! Collected (kind, type) tuples for complex types
19+
#:set CMPLX_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES))
1220

1321
#! Integer kinds to be considered during templating
1422
#:set INT_KINDS = ["int8", "int16", "int32", "int64"]
@@ -90,4 +98,44 @@ ${prefix + joinstr.join([line.strip() for line in txt.split("\n")]) + suffix}$
9098
#:enddef
9199

92100

101+
#! Generates a routine name from a generic name, rank, type and kind
102+
#!
103+
#! Args:
104+
#! gname (str): Generic name
105+
#! rank (integer): Rank if exist
106+
#! type (str): Type of the input
107+
#! kind (str): kind of inputs variable
108+
#! suffix (str): other identifier (could be used for output type/kind)
109+
#!
110+
#! Returns:
111+
#! A string with a new name
112+
#!
113+
#:def rname(gname, rank, type, kind, suffix='')
114+
$:"{0}_{1}_{2}{3}_{2}{3}".format(gname, rank, type[0], kind) if suffix == '' else "{0}_{1}_{2}{3}_{4}".format(gname, rank, type[0], kind, suffix)
115+
#:enddef
116+
117+
118+
#! Generates an array rank suffix for subarrays reducing the dimension
119+
#!
120+
#! Args:
121+
#! rank (int): Rank of the original variable
122+
#! selectors (array): Dimension and name of the variable(s)
123+
#!
124+
#! Returns:
125+
#! Array rank suffix string enclosed in braces
126+
#!
127+
#! E.g.,
128+
#! select_subarray(5 , [(4, 'i'), (5, 'j')])}$
129+
#! -> (:, :, :, i, j)
130+
#!
131+
#:def select_subarray(rank, selectors)
132+
#:assert rank > 0
133+
#:set seldict = dict(selectors)
134+
#:call join_lines(joinstr=", ", prefix="(", suffix=")")
135+
#:for i in range(1, rank + 1)
136+
$:seldict.get(i, ":")
137+
#:endfor
138+
#:endcall
139+
#:enddef
140+
93141
#:endmute

src/stdlib_experimental_io.fypp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

55
module 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

3232
contains
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

src/stdlib_experimental_io.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Loads a rank-2 `array` from a text file.
2020

2121
`filename`: Shall be a character expression containing the file name from which to load the rank-2 `array`.
2222

23-
`array`: Shall be an allocatable rank-2 array of type `real` or `integer`.
23+
`array`: Shall be an allocatable rank-2 array of type `real`, `complex` or `integer`.
2424

2525
### Return value
2626

@@ -104,7 +104,7 @@ Saves a rank-2 `array` into a text file.
104104

105105
`filename`: Shall be a character expression containing the name of the file that will contain the 2D `array`.
106106

107-
`array`: Shall be a rank-2 array of type `real` or `integer`.
107+
`array`: Shall be a rank-2 array of type `real`, `complex` or `integer`.
108108

109109
### Output
110110

src/stdlib_experimental_optval.f90

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

0 commit comments

Comments
 (0)