2
2
#:set RIL_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + LOG_KINDS_TYPES
3
3
submodule (stdlib_strings) stdlib_strings_format_string
4
4
5
+ use stdlib_optval, only: optval
5
6
implicit none
6
7
integer, parameter :: buffer_len = 512
7
8
@@ -12,40 +13,29 @@ contains
12
13
!! Format ${type}$ variable as character sequence
13
14
character(len=buffer_len) :: buffer
14
15
integer :: stat
15
- if(present(fmt)) then
16
- write(buffer, fmt, iostat=stat) val
17
- if(stat == 0) then
18
- string = trim(adjustl(buffer))
19
- else
20
- string = '*'
21
- !!\TODO: *?
22
- end if
16
+
17
+ write(buffer, optval(fmt, "g0"), iostat=stat) val
18
+ if (stat == 0) then
19
+ string = trim(buffer)
23
20
else
24
- write(buffer, *, iostat=stat) val
25
- if(stat == 0) then
26
- string = trim(adjustl(buffer))
27
- else
28
- string = '*'
29
- !!\TODO: *?
30
- end if
21
+ string = '*'
22
+ !!\TODO: *?
31
23
end if
24
+
32
25
end procedure format_string_${type[0]}$${kind}$
33
26
#:endfor
34
27
35
28
#:for kind, type in CMPLX_KINDS_TYPES
36
29
module procedure format_string_${type[0]}$${kind}$
37
30
!! Format ${type}$ variable as character sequence
38
31
character(len=buffer_len) :: buffer
39
- if(present(fmt)) then
40
- write(buffer, *) '('//&
41
- format_string_r${kind}$(real(val), fmt)//','// &
42
- format_string_r${kind}$(aimag(val), fmt)//')'
43
- else
44
- write(buffer, *) '('//&
45
- format_string_r${kind}$(real(val))//','// &
46
- format_string_r${kind}$(aimag(val))//')'
47
- end if
48
- string = trim(adjustl(buffer))
32
+
33
+ write(buffer, *) '('//&
34
+ format_string_r${kind}$(val%re, fmt)//','// &
35
+ format_string_r${kind}$(val%im, fmt)//')'
36
+
37
+ string = trim(buffer)
38
+
49
39
end procedure format_string_${type[0]}$${kind}$
50
40
#:endfor
51
41
0 commit comments