From 859e630a5435508610d032b59650dde09a8fcc8a Mon Sep 17 00:00:00 2001 From: lewis Date: Wed, 12 Jan 2022 20:03:12 +0000 Subject: [PATCH 01/12] Made format constants public --- src/stdlib_io.fypp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stdlib_io.fypp b/src/stdlib_io.fypp index a1af943d4..c338fac54 100644 --- a/src/stdlib_io.fypp +++ b/src/stdlib_io.fypp @@ -33,6 +33,9 @@ module stdlib_io FMT_COMPLEX_XDP = '(*(es26.18e3,1x,es26.18e3))', & FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))' + public :: FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_REAL_XDP, FMT_REAL_QP + public :: FMT_COMPLEX_SP, FMT_COMPLEX_DP, FMT_COMPLEX_XDP, FMT_COMPLEX_QP + !> Version: experimental !> !> Read a whole line from a formatted unit into a string variable From 0b818722977d0f9f4d8bb6522139c94ce17759d7 Mon Sep 17 00:00:00 2001 From: lewis Date: Wed, 12 Jan 2022 20:51:16 +0000 Subject: [PATCH 02/12] Added docs for formatting constants. --- doc/specs/stdlib_io.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 0c70be26e..da7bc3985 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -273,3 +273,44 @@ program demo_getline end do end program demo_getline ``` + +## Formatting constants + +### Status + +Experimental + +### Description + +Formatting constants for printing out integer, floating point, and complex numbers at their full precision. +Provides formats for all kinds as defined in stdlib_kinds + +### Example + +```fortran +program deom_fmt_constants + use intrinsic, iso_fortran_env, only : int32, int64, float32, float64 + use stdlib_io, only : FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP + implicit none + + integer(kind=int32) :: i32 + integer(kind=int64) :: i64 + real(kind=real32) :: r32 + real(kind=real64) :: r64 + complex(kind=real32) :: c32 + complex(kind=real64) :: c64 + + i32 = 100_int32 + i64 = 100_int64 + r32 = 100.0_real32 + r64 = 100.0_real64 + c32 = cmplx(100.0_real32, kind=real32) + c64 = cmplx(100.0_real64, kind=real64) + + print FMT_INT, i32, i64 + print FMT_REAL_SP, r32 + print FMT_REAL_DP, r64 + print FMT_COMPLEX_SP, c32 + print FMT_COMPLEX_DP, c64 + +``` From f7b3b286a3736c8231750b3d90eaefb2e0997f3e Mon Sep 17 00:00:00 2001 From: lewis Date: Wed, 12 Jan 2022 22:11:21 +0000 Subject: [PATCH 03/12] Removed repeating (*(...)) and 1x from format and refactored save_txt and load_txt to compensate. --- src/stdlib_io.fypp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/stdlib_io.fypp b/src/stdlib_io.fypp index c338fac54..b40afac58 100644 --- a/src/stdlib_io.fypp +++ b/src/stdlib_io.fypp @@ -23,15 +23,15 @@ module stdlib_io ! Format strings with edit descriptors for each type and kind character(*), parameter :: & - FMT_INT = '(*(i0,1x))', & - FMT_REAL_SP = '(*(es15.8e2,1x))', & - FMT_REAL_DP = '(*(es24.16e3,1x))', & - FMT_REAL_XDP = '(*(es26.18e3,1x))', & - FMT_REAL_QP = '(*(es44.35e4,1x))', & - FMT_COMPLEX_SP = '(*(es15.8e2,1x,es15.8e2))', & - FMT_COMPLEX_DP = '(*(es24.16e3,1x,es24.16e3))', & - FMT_COMPLEX_XDP = '(*(es26.18e3,1x,es26.18e3))', & - FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))' + FMT_INT = '(i0)', & + FMT_REAL_SP = '(es15.8e2)', & + FMT_REAL_DP = '(es24.16e3)', & + FMT_REAL_XDP = '(es26.18e3)', & + FMT_REAL_QP = '(es44.35e4)', & + FMT_COMPLEX_SP = '(es15.8e2,1x,es15.8e2)', & + FMT_COMPLEX_DP = '(es24.16e3,1x,es24.16e3)', & + FMT_COMPLEX_XDP = '(es26.18e3,1x,es26.18e3)', & + FMT_COMPLEX_QP = '(es44.35e4,1x,es44.35e4)' public :: FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_REAL_XDP, FMT_REAL_QP public :: FMT_COMPLEX_SP, FMT_COMPLEX_DP, FMT_COMPLEX_XDP, FMT_COMPLEX_QP @@ -115,9 +115,9 @@ contains allocate(d(nrow, ncol)) do i = 1, nrow #:if 'real' in t1 - read(s, FMT_REAL_${k1}$) d(i, :) + read(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))") d(i, :) #:elif 'complex' in t1 - read(s, FMT_COMPLEX_${k1}$) d(i, :) + read(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))") d(i, :) #:else read(s, *) d(i, :) #:endif @@ -153,11 +153,11 @@ contains s = open(filename, "w") do i = 1, size(d, 1) #:if 'real' in t1 - write(s, FMT_REAL_${k1}$) d(i, :) + write(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))") d(i, :) #:elif 'complex' in t1 - write(s, FMT_COMPLEX_${k1}$) d(i, :) + write(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))") d(i, :) #:elif 'integer' in t1 - write(s, FMT_INT) d(i, :) + write(s, "(*"//FMT_INT(1:len(FMT_INT)-1)//",1x))") d(i, :) #:else write(s, *) d(i, :) #:endif From 935050afbfce845f3c6b4bb73029ee88f0579559 Mon Sep 17 00:00:00 2001 From: lewis Date: Wed, 12 Jan 2022 22:13:36 +0000 Subject: [PATCH 04/12] Updated docs --- doc/specs/stdlib_io.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index da7bc3985..e2fcf7705 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -307,7 +307,7 @@ program deom_fmt_constants c32 = cmplx(100.0_real32, kind=real32) c64 = cmplx(100.0_real64, kind=real64) - print FMT_INT, i32, i64 + print "2("//FMT_INT//",1x)", i32, i64 print FMT_REAL_SP, r32 print FMT_REAL_DP, r64 print FMT_COMPLEX_SP, c32 From e9881baf081426087b486e44ec8e5bee1605c000 Mon Sep 17 00:00:00 2001 From: Lewis McMillan Date: Thu, 13 Jan 2022 09:06:04 +0000 Subject: [PATCH 05/12] Update doc/specs/stdlib_io.md Co-authored-by: Milan Curcic --- doc/specs/stdlib_io.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index e2fcf7705..2c069d93e 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -283,7 +283,7 @@ Experimental ### Description Formatting constants for printing out integer, floating point, and complex numbers at their full precision. -Provides formats for all kinds as defined in stdlib_kinds +Provides formats for all kinds as defined in the `stdlib_kinds` module. ### Example From 8333197aee010734014f9ab41616cba15c697c37 Mon Sep 17 00:00:00 2001 From: Lewis McMillan Date: Thu, 13 Jan 2022 09:06:14 +0000 Subject: [PATCH 06/12] Update doc/specs/stdlib_io.md Co-authored-by: Milan Curcic --- doc/specs/stdlib_io.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 2c069d93e..6d036261b 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -288,7 +288,7 @@ Provides formats for all kinds as defined in the `stdlib_kinds` module. ### Example ```fortran -program deom_fmt_constants +program demo_fmt_constants use intrinsic, iso_fortran_env, only : int32, int64, float32, float64 use stdlib_io, only : FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP implicit none From 05163c2a72235ee274d18bb0474a2572da45f498 Mon Sep 17 00:00:00 2001 From: Lewis McMillan Date: Thu, 13 Jan 2022 09:06:21 +0000 Subject: [PATCH 07/12] Update doc/specs/stdlib_io.md Co-authored-by: Milan Curcic --- doc/specs/stdlib_io.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 6d036261b..08a24741a 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -289,7 +289,7 @@ Provides formats for all kinds as defined in the `stdlib_kinds` module. ```fortran program demo_fmt_constants - use intrinsic, iso_fortran_env, only : int32, int64, float32, float64 + use, intrinsic :: iso_fortran_env, only : int32, int64, real32, real64 use stdlib_io, only : FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP implicit none From 8207d484e061356c42f886830e0a21b8df3a7339 Mon Sep 17 00:00:00 2001 From: Lewis McMillan Date: Thu, 13 Jan 2022 09:06:42 +0000 Subject: [PATCH 08/12] Update doc/specs/stdlib_io.md Co-authored-by: Milan Curcic --- doc/specs/stdlib_io.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 08a24741a..d605180ec 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -313,4 +313,5 @@ program demo_fmt_constants print FMT_COMPLEX_SP, c32 print FMT_COMPLEX_DP, c64 +end program demo_fmt_constants ``` From 51d61cc684312af42e9681f7f328a84611fe4c61 Mon Sep 17 00:00:00 2001 From: lewis Date: Thu, 13 Jan 2022 09:27:26 +0000 Subject: [PATCH 09/12] Added output example to docs for FMT constants. --- doc/specs/stdlib_io.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index d605180ec..c329c1c75 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -307,11 +307,11 @@ program demo_fmt_constants c32 = cmplx(100.0_real32, kind=real32) c64 = cmplx(100.0_real64, kind=real64) - print "2("//FMT_INT//",1x)", i32, i64 - print FMT_REAL_SP, r32 - print FMT_REAL_DP, r64 - print FMT_COMPLEX_SP, c32 - print FMT_COMPLEX_DP, c64 + print "(2("//FMT_INT//",1x))", i32, i64 ! outputs: 100 100 + print FMT_REAL_SP, r32 ! outputs: 1.00000000E+02 + print FMT_REAL_DP, r64 ! outputs: 1.0000000000000000E+002 + print FMT_COMPLEX_SP, c32 ! outputs: 1.00000000E+02 0.00000000E+00 + print FMT_COMPLEX_DP, c64 ! outputs: 1.0000000000000000E+002 0.0000000000000000E+000 end program demo_fmt_constants -``` +``` \ No newline at end of file From c7b75e18847e1a4ed0f9b057bdb6f659ca2f6a4c Mon Sep 17 00:00:00 2001 From: lewis Date: Thu, 13 Jan 2022 09:44:45 +0000 Subject: [PATCH 10/12] Updated CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3122b909..ef2522fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,9 @@ Changes to existing modules [#562](https://github.com/fortran-lang/stdlib/pull/562) - support for quadruple precision made optional [#565](https://github.com/fortran-lang/stdlib/pull/565) +- change in module `stdlib_io` + - Modified format constants, and made public + [#617](https://github.com/fortran-lang/stdlib/pull/617) # Version 0.1.0 From 97a91d9636d5debbafb161b96b0ba715c4a750b9 Mon Sep 17 00:00:00 2001 From: lewis Date: Mon, 17 Jan 2022 15:26:35 +0000 Subject: [PATCH 11/12] Added FORD doc markers to stdlib_io fmt specifiers. Changed iso_fortran_env to stdlib_kinds in spec file. --- doc/specs/stdlib_io.md | 24 ++++++++++++------------ src/stdlib_io.fypp | 14 +++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index c329c1c75..61b6d9578 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -289,23 +289,23 @@ Provides formats for all kinds as defined in the `stdlib_kinds` module. ```fortran program demo_fmt_constants - use, intrinsic :: iso_fortran_env, only : int32, int64, real32, real64 - use stdlib_io, only : FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP + use, stdlib_kinds, only : int32, int64, sp, dp + use stdlib_io, only : FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_COMPLEX_SP, FMT_COMPLEX_DP implicit none - integer(kind=int32) :: i32 - integer(kind=int64) :: i64 - real(kind=real32) :: r32 - real(kind=real64) :: r64 - complex(kind=real32) :: c32 - complex(kind=real64) :: c64 + integer(kind=int32) :: i32 + integer(kind=int64) :: i64 + real(kind=sp) :: r32 + real(kind=dp) :: r64 + complex(kind=sp) :: c32 + complex(kind=dp) :: c64 i32 = 100_int32 i64 = 100_int64 - r32 = 100.0_real32 - r64 = 100.0_real64 - c32 = cmplx(100.0_real32, kind=real32) - c64 = cmplx(100.0_real64, kind=real64) + r32 = 100.0_sp + r64 = 100.0_dp + c32 = cmplx(100.0_sp, kind=sp) + c64 = cmplx(100.0_dp, kind=dp) print "(2("//FMT_INT//",1x))", i32, i64 ! outputs: 100 100 print FMT_REAL_SP, r32 ! outputs: 1.00000000E+02 diff --git a/src/stdlib_io.fypp b/src/stdlib_io.fypp index b40afac58..9c37b2e4e 100644 --- a/src/stdlib_io.fypp +++ b/src/stdlib_io.fypp @@ -21,16 +21,28 @@ module stdlib_io ! Private API that is exposed so that we can test it in tests public :: parse_mode - ! Format strings with edit descriptors for each type and kind + !> Version: experimental + !> + !> Format strings with edit descriptors for each type and kind + !> The specification of this module is available [here](../page/specs/stdlib_io.html). character(*), parameter :: & + !> Format string for integers FMT_INT = '(i0)', & + !> Format string for single precision real numbers FMT_REAL_SP = '(es15.8e2)', & + !> Format string for souble precision real numbers FMT_REAL_DP = '(es24.16e3)', & + !> Format string for extended double precision real numbers FMT_REAL_XDP = '(es26.18e3)', & + !> Format string for quadruple precision real numbers FMT_REAL_QP = '(es44.35e4)', & + !> Format string for single precision complex numbers FMT_COMPLEX_SP = '(es15.8e2,1x,es15.8e2)', & + !> Format string for double precision complex numbers FMT_COMPLEX_DP = '(es24.16e3,1x,es24.16e3)', & + !> Format string for extended double precision complex numbers FMT_COMPLEX_XDP = '(es26.18e3,1x,es26.18e3)', & + !> Format string for quadruple precision complex numbers FMT_COMPLEX_QP = '(es44.35e4,1x,es44.35e4)' public :: FMT_INT, FMT_REAL_SP, FMT_REAL_DP, FMT_REAL_XDP, FMT_REAL_QP From 809c85c3a890ce082cb6ec75d61c187b087044d1 Mon Sep 17 00:00:00 2001 From: Lewis McMillan Date: Tue, 18 Jan 2022 18:44:57 +0000 Subject: [PATCH 12/12] Update src/stdlib_io.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_io.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_io.fypp b/src/stdlib_io.fypp index 9c37b2e4e..4909c550a 100644 --- a/src/stdlib_io.fypp +++ b/src/stdlib_io.fypp @@ -24,7 +24,7 @@ module stdlib_io !> Version: experimental !> !> Format strings with edit descriptors for each type and kind - !> The specification of this module is available [here](../page/specs/stdlib_io.html). + !> ([Specification](../page/specs/stdlib_io.html)) character(*), parameter :: & !> Format string for integers FMT_INT = '(i0)', &