22#:set RIL_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + LOG_KINDS_TYPES
33submodule (stdlib_strings) stdlib_strings_format_string
44
5+ use stdlib_optval, only: optval
56 implicit none
67 integer, parameter :: buffer_len = 512
78
@@ -12,40 +13,29 @@ contains
1213 !! Format ${type}$ variable as character sequence
1314 character(len=buffer_len) :: buffer
1415 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)
2320 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: *?
3123 end if
24+
3225 end procedure format_string_${type[0]}$${kind}$
3326 #:endfor
3427
3528 #:for kind, type in CMPLX_KINDS_TYPES
3629 module procedure format_string_${type[0]}$${kind}$
3730 !! Format ${type}$ variable as character sequence
3831 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+
4939 end procedure format_string_${type[0]}$${kind}$
5040 #:endfor
5141
0 commit comments