Skip to content

Commit c622a5b

Browse files
committed
fix format_string routines update its doc.
fix: 1. src/stdlib_strings.fypp%format_string interface comments 2. src/stdlib_strings_format_string.fypp update: 1. src/tests/string/test_strings_format_string.f90 2. doc/specs/stdlib_strings.md note: make passed cmake passed
1 parent da2881c commit c622a5b

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

doc/specs/stdlib_strings.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Format or transfer a integer/real/complex/logical variable as a character sequen
339339

340340
#### Syntax
341341

342-
`format_string = [[stdlib_strings(module):format_string(interface)]] (value[, format])`
342+
`format_string = [[stdlib_strings(module):format_string(interface)]] (value [, format])`
343343

344344
#### Status
345345

@@ -367,24 +367,43 @@ program demo_strings_format_string
367367
use, non_intrinsic :: stdlib_strings, only: format_string
368368
implicit none
369369
print *, 'format_string(complex) : '
370-
print *, format_string((1, 1)) ! (1.00000000,1.00000000)
371-
print *, format_string((1, 1), '(F6.2)') ! (1.00,1.00)
372-
print *, format_string((1, 1), '(F6.2)'), format_string((2, 2), '(F7.3)') ! (1.00,1.00)(2.000,2.000)
370+
print *, format_string((1, 1))
371+
print *, format_string((1, 1), '(F6.2)')
372+
print *, format_string((1, 1), '(F6.2)'), format_string((2, 2), '(F7.3)')
373373
print *, 'format_string(integer) : '
374-
print *, format_string(100) ! 100
375-
print *, format_string(100, '(I6)') ! 100
376-
print *, format_string(100, '(I6)'), format_string(1000, '(I7)') ! 1001000
374+
print *, format_string(100)
375+
print *, format_string(100, '(I6)')
376+
print *, format_string(100, '(I6)'), format_string(1000, '(I7)')
377377
print *, 'format_string(real) : '
378-
print *, format_string(100.) ! 100.000000
379-
print *, format_string(100., '(F6.2)') ! 100.00
378+
print *, format_string(100.)
379+
print *, format_string(100., '(F12.2)')
380380
print *, format_string(100., '(F6.2)'), &
381-
format_string(1000., '(F7.3)'), format_string(1000, '(F7.3)') ! 100.00********
381+
format_string(1000., '(F7.3)'), format_string(1000, '(F7.3)')
382382
!! Wrong demonstration
383383
print *, 'format_string(logical) : '
384-
print *, format_string(.true.) ! T
385-
print *, format_string(.true., '(L2)') ! T
384+
print *, format_string(.true.)
385+
print *, format_string(.true., '(L2)')
386386
print *, format_string(.false., '(L2)'), format_string(.true., '(L5)'), &
387-
format_string(.false., '(I5)') ! FT*
387+
format_string(.false., '(I5)')
388388
!! Wrong demonstration
389389
end program demo_strings_format_string
390390
```
391+
**Results**
392+
```fortran
393+
format_string(complex) :
394+
(1.00000000,1.00000000)
395+
( 1.00, 1.00)
396+
( 1.00, 1.00) ( 2.000, 2.000)
397+
format_string(integer) :
398+
100
399+
100
400+
100 1000
401+
format_string(real) :
402+
100.000000
403+
100.00
404+
100.00********
405+
format_string(logical) :
406+
T
407+
T
408+
F T*
409+
```

src/stdlib_strings.fypp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module stdlib_strings
2121
interface format_string
2222
!! version: experimental
2323
!!
24-
!! Format ${type}$ variable as character sequence
25-
!! ([Specification](../page/specs/stdlib_string.html#description))
24+
!! Format other types as character sequence.
25+
!! ([Specification](../page/specs/stdlib_strings.html#description))
2626
#:for kind, type in KINDS_TYPES
2727
pure module function format_string_${type[0]}$${kind}$(val, fmt) result(string)
2828
character(len=:), allocatable :: string

src/stdlib_strings_format_string.fypp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#:set RIL_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + LOG_KINDS_TYPES
33
submodule (stdlib_strings) stdlib_strings_format_string
44

5-
use stdlib_optval, only: optval
65
implicit none
76
integer, parameter :: buffer_len = 512
87

@@ -14,7 +13,7 @@ contains
1413
character(len=buffer_len) :: buffer
1514
integer :: stat
1615

17-
write(buffer, optval(fmt, "g0"), iostat=stat) val
16+
write(buffer, optval(fmt, "(g0)"), iostat=stat) val
1817
if (stat == 0) then
1918
string = trim(buffer)
2019
else

src/tests/string/test_strings_format_string.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ program test_strings_format_string
1111
print *, format_string(100, '(I6)'), format_string(1000, '(I7)')
1212
print *, 'format_string(real) : '
1313
print *, format_string(100.)
14-
print *, format_string(100., '(F6.2)')
14+
print *, format_string(100., '(F12.2)')
1515
print *, format_string(100., '(F6.2)'), &
1616
format_string(1000., '(F7.3)'), format_string(1000, '(F7.3)')
1717
!! Wrong demonstration

0 commit comments

Comments
 (0)