Skip to content

Commit 909d492

Browse files
authored
Merge branch 'master' into add_close
2 parents 9cebec7 + 47d0a00 commit 909d492

21 files changed

+530
-268
lines changed

CONTRIBUTORS.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Fortran stdlib developers
3+
Copyright (c) 2019-2021 stdlib contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

doc/specs/stdlib_ascii.md

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,42 +212,4 @@ program demo_reverse
212212
implicit none
213213
print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH"
214214
end program demo_reverse
215-
```
216-
217-
### `to_string`
218-
219-
#### Status
220-
221-
Experimental
222-
223-
#### Description
224-
225-
Create a character string representing the value of the provided variable.
226-
227-
#### Syntax
228-
229-
`res = [[stdlib_ascii(module):to_string(interface)]] (string)`
230-
231-
#### Class
232-
233-
Pure function.
234-
235-
#### Argument
236-
237-
`val`: shall be an intrinsic integer or logical type. It is an `intent(in)` argument.
238-
239-
#### Result value
240-
241-
The result is an intrinsic character type.
242-
243-
#### Example
244-
245-
```fortran
246-
program demo_string_value
247-
use stdlib_ascii, only : to_string
248-
implicit none
249-
print'(a)', to_string(-3) ! returns "-3"
250-
print'(a)', to_string(.true.) ! returns "T"
251-
print'(a)', to_string(42) ! returns "42"
252-
end program demo_string_value
253-
```
215+
```

doc/specs/stdlib_linalg.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,58 @@ end program demo_diag5
101101

102102
Experimental
103103

104+
### Class
105+
106+
Pure function.
107+
104108
### Description
105109

106-
Construct the identity matrix
110+
Construct the identity matrix.
107111

108112
### Syntax
109113

110-
`I = [[stdlib_linalg(module):eye(function)]](n)`
114+
`I = [[stdlib_linalg(module):eye(function)]](dim1 [, dim2])`
111115

112116
### Arguments
113117

114-
`n`: Shall be a scalar of default type `integer`.
118+
`dim1`: Shall be a scalar of default type `integer`.
119+
This is an `intent(in)` argument.
120+
121+
`dim2`: Shall be a scalar of default type `integer`.
122+
This is an `intent(in)` and `optional` argument.
115123

116124
### Return value
117125

118-
Returns the identity matrix, i.e. a square matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer(int8)`.
126+
Return the identity matrix, i.e. a matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer(int8)`.
127+
The use of `int8` was suggested to save storage.
128+
129+
#### Warning
130+
131+
Since the result of `eye` is of `integer(int8)` type, one should be careful about using it in arithmetic expressions. For example:
132+
```fortran
133+
real :: A(:,:)
134+
!> Be careful
135+
A = eye(2,2)/2 !! A == 0.0
136+
!> Recommend
137+
A = eye(2,2)/2.0 !! A == diag([0.5, 0.5])
138+
```
119139

120140
### Example
121141

122142
```fortran
123143
program demo_eye1
124144
use stdlib_linalg, only: eye
125145
implicit none
146+
integer :: i(2,2)
126147
real :: a(3,3)
127-
A = eye(3)
148+
real :: b(2,3) !! Matrix is non-square.
149+
complex :: c(2,2)
150+
I = eye(2) !! [1,0; 0,1]
151+
A = eye(3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
152+
A = eye(3,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
153+
B = eye(2,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0]
154+
C = eye(2,2) !! [(1.0,0.0),(0.0,0.0); (0.0,0.0),(1.0,0.0)]
155+
C = (1.0,1.0)*eye(2,2) !! [(1.0,1.0),(0.0,0.0); (0.0,0.0),(1.0,1.0)]
128156
end program demo_eye1
129157
```
130158

doc/specs/stdlib_strings.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,72 @@ program demo_count
538538
539539
end program demo_count
540540
```
541+
542+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
543+
### `to_string`
544+
545+
#### Description
546+
547+
Format or transfer a `integer/real/complex/logical` scalar as a string.
548+
Input a wrong `format` that cause the internal-IO to fail, the result value is a string of `[*]`.
549+
550+
#### Syntax
551+
552+
`string = [[stdlib_strings(module):to_string(interface)]] (value [, format])`
553+
554+
#### Status
555+
556+
Experimental
557+
558+
#### Class
559+
560+
Pure function.
561+
562+
#### Argument
563+
564+
- `value`: Shall be an `integer/real/complex/logical` scalar.
565+
This is an `intent(in)` argument.
566+
- `format`: Shall be a `character(len=*)` scalar like `'(F6.2)'` or just `'F6.2'`.
567+
This is an `intent(in)` and `optional` argument.
568+
Contains the edit descriptor to format `value` into a string, for example `'(F6.2)'` or `'(f6.2)'`.
569+
`to_string` will automatically enclose `format` in a set of parentheses, so passing `F6.2` or `f6.2` as `format` is possible as well.
570+
571+
#### Result value
572+
573+
The result is an `allocatable` length `character` scalar with up to `128` cached `character` length.
574+
575+
#### Example
576+
577+
```fortran
578+
program demo_to_string
579+
use stdlib_strings, only: to_string
580+
581+
!> Example for `complex` type
582+
print *, to_string((1, 1)) !! "(1.00000000,1.00000000)"
583+
print *, to_string((1, 1), '(F6.2)') !! "( 1.00, 1.00)"
584+
print *, to_string((1000, 1), '(ES0.2)'), to_string((1000, 1), '(SP,F6.3)')
585+
!! "(1.00E+3,1.00)""(******,+1.000)"
586+
!! Too narrow formatter for real number
587+
!! Normal demonstration(`******` from Fortran Standard)
588+
589+
!> Example for `integer` type
590+
print *, to_string(-3) !! "-3"
591+
print *, to_string(42, '(I4)') !! " 42"
592+
print *, to_string(1, '(I0.4)'), to_string(2, '(B4)') !! "0001"" 10"
593+
594+
!> Example for `real` type
595+
print *, to_string(1.) !! "1.00000000"
596+
print *, to_string(1., '(F6.2)') !! " 1.00"
597+
print *, to_string(1., 'F6.2') !! " 1.00"
598+
print *, to_string(1., '(SP,ES9.2)'), to_string(1, '(F7.3)') !! "+1.00E+00""[*]"
599+
!! 1 wrong demonstration (`[*]` from `to_string`)
600+
601+
!> Example for `logical` type
602+
print *, to_string(.true.) !! "T"
603+
print *, to_string(.true., '(L2)') !! " T"
604+
print *, to_string(.true., 'L2') !! " T"
605+
print *, to_string(.false., '(I5)') !! "[*]"
606+
!! 1 wrong demonstrations(`[*]` from `to_string`)
607+
608+
end program demo_to_string
609+
```

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ set(fppFiles
3535
stdlib_math_arange.fypp
3636
stdlib_math_is_close.fypp
3737
stdlib_string_type.fypp
38+
stdlib_string_type_constructor.fypp
39+
stdlib_strings_to_string.fypp
40+
stdlib_strings.fypp
3841
)
3942

4043

@@ -53,7 +56,6 @@ set(SRC
5356
stdlib_error.f90
5457
stdlib_kinds.f90
5558
stdlib_logger.f90
56-
stdlib_strings.f90
5759
stdlib_system.F90
5860
stdlib_specialfunctions.f90
5961
stdlib_specialfunctions_legendre.f90

src/Makefile.manual

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SRCFYPP =\
1+
SRCFYPP = \
22
stdlib_ascii.fypp \
33
stdlib_bitsets_64.fypp \
44
stdlib_bitsets_large.fypp \
@@ -27,11 +27,14 @@ SRCFYPP =\
2727
stdlib_stats_moment_scalar.fypp \
2828
stdlib_stats_var.fypp \
2929
stdlib_math.fypp \
30-
stdlib_math_linspace.fypp \
31-
stdlib_math_logspace.fypp \
30+
stdlib_math_linspace.fypp \
31+
stdlib_math_logspace.fypp \
3232
stdlib_math_is_close.fypp \
3333
stdlib_stats_distribution_PRNG.fypp \
34-
stdlib_string_type.fypp
34+
stdlib_string_type.fypp \
35+
stdlib_string_type_constructor.fypp \
36+
stdlib_strings.fypp \
37+
stdlib_strings_to_string.fypp
3538

3639
SRC = f18estop.f90 \
3740
stdlib_error.f90 \
@@ -41,7 +44,6 @@ SRC = f18estop.f90 \
4144
stdlib_kinds.f90 \
4245
stdlib_logger.f90 \
4346
stdlib_quadrature_gauss.f90 \
44-
stdlib_strings.f90 \
4547
$(SRCGEN)
4648

4749
LIB = libstdlib.a
@@ -78,85 +80,89 @@ stdlib_error.o: stdlib_optval.o
7880
stdlib_specialfunctions.o: stdlib_kinds.o
7981
stdlib_specialfunctions_legendre.o: stdlib_kinds.o stdlib_specialfunctions.o
8082
stdlib_io.o: \
81-
stdlib_ascii.o \
82-
stdlib_error.o \
83-
stdlib_optval.o \
84-
stdlib_kinds.o
83+
stdlib_ascii.o \
84+
stdlib_error.o \
85+
stdlib_optval.o \
86+
stdlib_kinds.o \
87+
stdlib_ascii.o
8588
stdlib_linalg.o: \
86-
stdlib_kinds.o
89+
stdlib_kinds.o
8790
stdlib_linalg_diag.o: \
88-
stdlib_linalg.o \
89-
stdlib_kinds.o
91+
stdlib_linalg.o \
92+
stdlib_kinds.o
9093
stdlib_logger.o: stdlib_ascii.o stdlib_optval.o
9194
stdlib_optval.o: stdlib_kinds.o
9295
stdlib_quadrature.o: stdlib_kinds.o
93-
9496
stdlib_quadrature_gauss.o: stdlib_kinds.o stdlib_quadrature.o
95-
9697
stdlib_quadrature_simps.o: \
97-
stdlib_quadrature.o \
98-
stdlib_error.o \
99-
stdlib_kinds.o
98+
stdlib_quadrature.o \
99+
stdlib_error.o \
100+
stdlib_kinds.o
100101
stdlib_quadrature_trapz.o: \
101-
stdlib_quadrature.o \
102-
stdlib_error.o \
103-
stdlib_kinds.o
102+
stdlib_quadrature.o \
103+
stdlib_error.o \
104+
stdlib_kinds.o
104105
stdlib_sorting.o: \
105-
stdlib_kinds.o \
106-
stdlib_string_type.o
106+
stdlib_kinds.o \
107+
stdlib_string_type.o
107108
stdlib_sorting_ord_sort.o: \
108-
stdlib_sorting.o
109+
stdlib_sorting.o
109110
stdlib_sorting_sort.o: \
110-
stdlib_sorting.o
111+
stdlib_sorting.o
111112
stdlib_sorting_sort_index.o: \
112-
stdlib_sorting.o
113+
stdlib_sorting.o
113114
stdlib_stats.o: \
114-
stdlib_kinds.o
115+
stdlib_kinds.o
115116
stdlib_stats_corr.o: \
116-
stdlib_optval.o \
117-
stdlib_kinds.o \
118-
stdlib_stats.o
117+
stdlib_optval.o \
118+
stdlib_kinds.o \
119+
stdlib_stats.o
119120
stdlib_stats_cov.o: \
120-
stdlib_optval.o \
121-
stdlib_kinds.o \
122-
stdlib_stats.o
121+
stdlib_optval.o \
122+
stdlib_kinds.o \
123+
stdlib_stats.o
123124
stdlib_stats_mean.o: \
124-
stdlib_optval.o \
125-
stdlib_kinds.o \
126-
stdlib_stats.o
125+
stdlib_optval.o \
126+
stdlib_kinds.o \
127+
stdlib_stats.o
127128
stdlib_stats_median.o: \
128-
stdlib_optval.o \
129-
stdlib_kinds.o \
130-
stdlib_sorting.o \
131-
stdlib_stats.o
129+
stdlib_optval.o \
130+
stdlib_kinds.o \
131+
stdlib_sorting.o \
132+
stdlib_stats.o
132133
stdlib_stats_moment.o: \
133-
stdlib_optval.o \
134-
stdlib_kinds.o \
135-
stdlib_stats.o
134+
stdlib_optval.o \
135+
stdlib_kinds.o \
136+
stdlib_stats.o
136137
stdlib_stats_moment_all.o: \
137-
stdlib_stats_moment.o
138+
stdlib_stats_moment.o
138139
stdlib_stats_moment_mask.o: \
139-
stdlib_stats_moment.o
140+
stdlib_stats_moment.o
140141
stdlib_stats_moment_scalar.o: \
141-
stdlib_stats_moment.o
142+
stdlib_stats_moment.o
142143
stdlib_stats_var.o: \
143-
stdlib_optval.o \
144-
stdlib_kinds.o \
145-
stdlib_stats.o
144+
stdlib_optval.o \
145+
stdlib_kinds.o \
146+
stdlib_stats.o
146147
stdlib_stats_distribution_PRNG.o: \
147-
stdlib_kinds.o \
148-
stdlib_error.o
148+
stdlib_kinds.o \
149+
stdlib_error.o
149150
stdlib_string_type.o: stdlib_ascii.o \
150151
stdlib_kinds.o
152+
stdlib_string_type_constructor.o: stdlib_string_type.o \
153+
stdlib_strings_to_string.o \
154+
stdlib_strings.o
151155
stdlib_strings.o: stdlib_ascii.o \
152156
stdlib_string_type.o \
153-
stdlib_optval.o
157+
stdlib_optval.o \
158+
stdlib_kinds.o
159+
stdlib_strings_to_string.o: stdlib_strings.o
154160
stdlib_math.o: stdlib_kinds.o \
155161
stdlib_optval.o
156162
stdlib_math_linspace.o: \
157-
stdlib_math.o
163+
stdlib_math.o
158164
stdlib_math_logspace.o: \
159-
stdlib_math_linspace.o
165+
stdlib_math_linspace.o
160166
stdlib_math_arange.o: \
161167
stdlib_math.o
162168
stdlib_linalg_outer_product.o: stdlib_linalg.o

0 commit comments

Comments
 (0)