From a3df7b63de8aee75f47575cd59958f6702bbb42c Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Tue, 26 Dec 2023 15:52:45 +0100 Subject: [PATCH 1/6] Support of fypp for stdlib_str2num --- src/CMakeLists.txt | 2 +- src/{stdlib_str2num.f90 => stdlib_str2num.fypp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{stdlib_str2num.f90 => stdlib_str2num.fypp} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4fdf49b64..0c2f76c8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,7 @@ set(fppFiles stdlib_math_is_close.fypp stdlib_math_all_close.fypp stdlib_math_diff.fypp + stdlib_str2num.fypp stdlib_string_type.fypp stdlib_string_type_constructor.fypp stdlib_strings_to_string.fypp @@ -82,7 +83,6 @@ set(SRC stdlib_specialfunctions_legendre.f90 stdlib_quadrature_gauss.f90 stdlib_stringlist_type.f90 - stdlib_str2num.f90 ${outFiles} ) diff --git a/src/stdlib_str2num.f90 b/src/stdlib_str2num.fypp similarity index 100% rename from src/stdlib_str2num.f90 rename to src/stdlib_str2num.fypp From ea2ee725c6009a6153cc2fde326a8c810a466e88 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Tue, 26 Dec 2023 17:29:20 +0100 Subject: [PATCH 2/6] add fypp directives for qp --- src/stdlib_str2num.fypp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/stdlib_str2num.fypp b/src/stdlib_str2num.fypp index 68f1e9510..d4a76cf32 100644 --- a/src/stdlib_str2num.fypp +++ b/src/stdlib_str2num.fypp @@ -22,7 +22,7 @@ !> difference rel : 0.3300E-029% module stdlib_str2num - use iso_fortran_env, only: sp => real32, dp => real64, qp => real128 + use stdlib_kinds, only: sp, dp, qp, int8, int32 use ieee_arithmetic implicit none private @@ -46,21 +46,27 @@ module stdlib_str2num module procedure to_int module procedure to_float module procedure to_double +#:if WITH_QP module procedure to_quad +#:endif end interface interface to_num_p module procedure to_int_p module procedure to_float_p module procedure to_double_p +#:if WITH_QP module procedure to_quad_p +#:endif end interface interface to_num_base module procedure to_int_32 module procedure to_real_sp module procedure to_real_dp +#:if WITH_QP module procedure to_real_qp +#:endif end interface contains @@ -153,6 +159,7 @@ module stdlib_str2num if(present(stat)) stat = err end function +#:if WITH_QP function to_quad(s,mold) result(r) ! -- In/out Variables character(*), intent(in) :: s !> input string @@ -180,6 +187,7 @@ module stdlib_str2num s => s(p:) if(present(stat)) stat = err end function +#:endif !--------------------------------------------- ! String To Number Implementations @@ -400,6 +408,7 @@ module stdlib_str2num stat = 0 end subroutine +#:if WITH_QP subroutine to_real_qp(s,v,p,stat) integer, parameter :: wp = qp !> Sequentially unroll the character and get the sub integers composing the whole number, fraction and exponent @@ -502,6 +511,7 @@ module stdlib_str2num end if stat = 0 end subroutine +#:endif !--------------------------------------------- ! Internal Utility functions @@ -529,4 +539,4 @@ module stdlib_str2num end do end function -end module stdlib_str2num \ No newline at end of file +end module stdlib_str2num From 1585c10dfad254542bd5db2bb01b5a1372b4c12d Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Tue, 26 Dec 2023 17:41:54 +0100 Subject: [PATCH 3/6] addition of fypp directives for some integer procedures --- src/stdlib_str2num.fypp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stdlib_str2num.fypp b/src/stdlib_str2num.fypp index d4a76cf32..dae8865f9 100644 --- a/src/stdlib_str2num.fypp +++ b/src/stdlib_str2num.fypp @@ -1,3 +1,4 @@ +#:include "common.fypp" !> The `stdlib_str2num` module provides procedures and interfaces for conversion !> of characters to numerical types. Currently supported: int32, real32 and real64 !> @@ -61,7 +62,9 @@ module stdlib_str2num end interface interface to_num_base - module procedure to_int_32 + #:for k1, t1 in INT_KINDS_TYPES + module procedure to_${k1}$ + #:endfor module procedure to_real_sp module procedure to_real_dp #:if WITH_QP @@ -193,11 +196,12 @@ module stdlib_str2num ! String To Number Implementations !--------------------------------------------- - elemental subroutine to_int_32(s,v,p,stat) + #:for k1, t1 in INT_KINDS_TYPES + elemental subroutine to_${k1}$(s,v,p,stat) !> Return an unsigned 32-bit integer ! -- In/out Variables character(*), intent(in) :: s !> input string - integer(int32), intent(inout) :: v !> Output real value + ${t1}$, intent(out) :: v !> Output real value integer(int8), intent(out) :: p !> position within the number integer(int8), intent(out) :: stat !> status upon succes or failure to read ! -- Internal Variables @@ -219,6 +223,7 @@ module stdlib_str2num end do stat = 0 end subroutine + #:endfor elemental subroutine to_real_sp(s,v,p,stat) integer, parameter :: wp = sp @@ -520,7 +525,7 @@ module stdlib_str2num elemental function mvs2nwsp(s) result(p) !> move string to position of the next non white space character character(*),intent(in) :: s !> character chain - integer(1) :: p !> position + integer(int8) :: p !> position !---------------------------------------------- p = 1 do while( p Date: Tue, 26 Dec 2023 17:48:25 +0100 Subject: [PATCH 4/6] Addition of fypp directives for some integer procedures --- src/stdlib_str2num.fypp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/stdlib_str2num.fypp b/src/stdlib_str2num.fypp index dae8865f9..930d27fdc 100644 --- a/src/stdlib_str2num.fypp +++ b/src/stdlib_str2num.fypp @@ -44,7 +44,9 @@ module stdlib_str2num integer(kind=ikind), parameter :: LF = 10, CR = 13, WS = 32 interface to_num - module procedure to_int + #:for k1, t1 in INT_KINDS_TYPES + module procedure to_${k1}$ + #:endfor module procedure to_float module procedure to_double #:if WITH_QP @@ -53,7 +55,9 @@ module stdlib_str2num end interface interface to_num_p - module procedure to_int_p + #:for k1, t1 in INT_KINDS_TYPES + module procedure to_${k1}$_p + #:endfor module procedure to_float_p module procedure to_double_p #:if WITH_QP @@ -78,33 +82,35 @@ module stdlib_str2num ! String To Number interfaces !--------------------------------------------- - elemental function to_int(s,mold) result(v) + #:for k1, t1 in INT_KINDS_TYPES + elemental function to_${k1}$(s,mold) result(v) ! -- In/out Variables character(*), intent(in) :: s !> input string - integer, intent(in) :: mold !> dummy argument to disambiguate at compile time the generic interface - integer :: v !> Output integer 32 value + ${t1}$, intent(in) :: mold !> dummy argument to disambiguate at compile time the generic interface + ${t1}$ :: v !> Output integer 32 value ! -- Internal Variables - integer(1) :: p !> position within the number - integer(1) :: stat !> error status + integer(int8) :: p !> position within the number + integer(int8) :: stat !> error status !---------------------------------------------- call to_num_base(s,v,p,stat) end function - function to_int_p(s,mold,stat) result(v) + function to_${k1}$_p(s,mold,stat) result(v) ! -- In/out Variables character(len=:), pointer :: s !> input string - integer, intent(in) :: mold !> dummy argument to disambiguate at compile time the generic interface - integer :: v !> Output integer 32 value - integer(1),intent(inout), optional :: stat + ${t1}$, intent(in) :: mold !> dummy argument to disambiguate at compile time the generic interface + ${t1}$ :: v !> Output ${t1}$ value + integer(int8),intent(inout), optional :: stat ! -- Internal Variables - integer(1) :: p !> position within the number - integer(1) :: err + integer(int8) :: p !> position within the number + integer(int8) :: err !---------------------------------------------- call to_num_base(s,v,p,err) p = min( p , len(s) ) s => s(p:) if(present(stat)) stat = err end function + #:endfor elemental function to_float(s,mold) result(r) ! -- In/out Variables From ad0bb718ca2bc177d30a8954958e0118cebf3418 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Tue, 26 Dec 2023 18:30:41 +0100 Subject: [PATCH 5/6] fix issue --- src/stdlib_str2num.fypp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stdlib_str2num.fypp b/src/stdlib_str2num.fypp index 930d27fdc..fd9b241c8 100644 --- a/src/stdlib_str2num.fypp +++ b/src/stdlib_str2num.fypp @@ -23,7 +23,7 @@ !> difference rel : 0.3300E-029% module stdlib_str2num - use stdlib_kinds, only: sp, dp, qp, int8, int32 + use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64 use ieee_arithmetic implicit none private @@ -67,7 +67,7 @@ module stdlib_str2num interface to_num_base #:for k1, t1 in INT_KINDS_TYPES - module procedure to_${k1}$ + module procedure to_int_${k1}$ #:endfor module procedure to_real_sp module procedure to_real_dp @@ -203,7 +203,7 @@ module stdlib_str2num !--------------------------------------------- #:for k1, t1 in INT_KINDS_TYPES - elemental subroutine to_${k1}$(s,v,p,stat) + elemental subroutine to_int_${k1}$(s,v,p,stat) !> Return an unsigned 32-bit integer ! -- In/out Variables character(*), intent(in) :: s !> input string From 17d3dae881bbac8d75050027069a1b977b5064b8 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Tue, 26 Dec 2023 18:59:54 +0100 Subject: [PATCH 6/6] support of fypp for test_to_number --- test/string/CMakeLists.txt | 2 ++ ...t_string_to_number.f90 => test_string_to_number.fypp} | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) rename test/string/{test_string_to_number.f90 => test_string_to_number.fypp} (98%) diff --git a/test/string/CMakeLists.txt b/test/string/CMakeLists.txt index f8e3c2323..833471c9e 100644 --- a/test/string/CMakeLists.txt +++ b/test/string/CMakeLists.txt @@ -3,6 +3,7 @@ # Create a list of the files to be preprocessed set(fppFiles test_string_assignment.fypp + test_string_to_number.fypp ) fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) @@ -14,4 +15,5 @@ ADDTEST(string_match) ADDTEST(string_derivedtype_io) ADDTEST(string_functions) ADDTEST(string_strip_chomp) +ADDTEST(string_to_number) ADDTEST(string_to_string) diff --git a/test/string/test_string_to_number.f90 b/test/string/test_string_to_number.fypp similarity index 98% rename from test/string/test_string_to_number.f90 rename to test/string/test_string_to_number.fypp index 36e749182..1f2190f5b 100644 --- a/test/string/test_string_to_number.f90 +++ b/test/string/test_string_to_number.fypp @@ -1,5 +1,5 @@ module test_string_to_number - use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128 + use stdlib_kinds, only: sp, dp, qp use stdlib_str2num use testdrive, only : new_unittest, unittest_type, error_type, check implicit none @@ -14,6 +14,9 @@ subroutine collect_string_to_number(testsuite) testsuite = [ & new_unittest("to_float", test_to_float), & new_unittest("to_double", test_to_double) & +#:if WITH_QP + , new_unittest("to_quadruple", test_to_quadruple) & +#:endif ] end subroutine collect_string_to_number @@ -215,6 +218,7 @@ logical function ucheck(s) end function end subroutine +#:if WITH_QP subroutine test_to_quadruple(error) use stdlib_str2num type(error_type), allocatable, intent(out) :: error @@ -313,6 +317,7 @@ logical function ucheck(s) end if end function end subroutine +#:endif end module test_string_to_number @@ -340,4 +345,4 @@ program tester write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!" error stop end if -end program \ No newline at end of file +end program