diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90bd8e1ed..106fa02ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ # Create a list of the files to be preprocessed set(fppFiles stdlib_experimental_io.fypp + stdlib_experimental_optval.fypp stdlib_experimental_stats.fypp stdlib_experimental_stats_mean.fypp ) @@ -21,10 +22,8 @@ fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) set(SRC stdlib_experimental_ascii.f90 - stdlib_experimental_io.f90 stdlib_experimental_error.f90 stdlib_experimental_kinds.f90 - stdlib_experimental_optval.f90 stdlib_experimental_system.F90 ${outFiles} ) diff --git a/src/common.fypp b/src/common.fypp index b0c716104..85d82704c 100644 --- a/src/common.fypp +++ b/src/common.fypp @@ -9,6 +9,14 @@ #! Collected (kind, type) tuples for real types #:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES)) +#! Complex kinds to be considered during templating +#:set CMPLX_KINDS = ["sp", "dp", "qp"] + +#! Complex types to be considere during templating +#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS] + +#! Collected (kind, type) tuples for complex types +#:set CMPLX_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES)) #! Integer kinds to be considered during templating #:set INT_KINDS = ["int8", "int16", "int32", "int64"] diff --git a/src/stdlib_experimental_io.fypp b/src/stdlib_experimental_io.fypp index c51a8e792..2031afd1b 100644 --- a/src/stdlib_experimental_io.fypp +++ b/src/stdlib_experimental_io.fypp @@ -1,6 +1,6 @@ #:include "common.fypp" -#:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES +#:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + CMPLX_KINDS_TYPES module stdlib_experimental_io @@ -18,21 +18,21 @@ module stdlib_experimental_io public :: parse_mode interface loadtxt - #:for k1, _ in KINDS_TYPES - module procedure loadtxt_${k1}$ + #:for k1, t1 in KINDS_TYPES + module procedure loadtxt_${t1[0]}$${k1}$ #:endfor end interface loadtxt interface savetxt - #:for k1, _ in KINDS_TYPES - module procedure savetxt_${k1}$ + #:for k1, t1 in KINDS_TYPES + module procedure savetxt_${t1[0]}$${k1}$ #:endfor end interface contains #:for k1, t1 in KINDS_TYPES - subroutine loadtxt_${k1}$(filename, d) + subroutine loadtxt_${t1[0]}$${k1}$(filename, d) ! Loads a 2D array from a text file. ! ! Arguments @@ -58,7 +58,7 @@ contains ! ... ! integer :: s - integer :: nrow,ncol,i + integer :: nrow, ncol, i s = open(filename) @@ -74,12 +74,12 @@ contains end do close(s) - end subroutine loadtxt_${k1}$ + end subroutine loadtxt_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in KINDS_TYPES - subroutine savetxt_${k1}$(filename, d) + subroutine savetxt_${t1[0]}$${k1}$(filename, d) ! Saves a 2D array into a text file. ! ! Arguments @@ -100,13 +100,13 @@ contains write(s, *) d(i, :) end do close(s) - end subroutine savetxt_${k1}$ + end subroutine savetxt_${t1[0]}$${k1}$ #:endfor integer function number_of_columns(s) ! determine number of columns - integer,intent(in)::s + integer,intent(in) :: s integer :: ios character :: c @@ -126,23 +126,33 @@ contains end function number_of_columns - integer function number_of_rows_numeric(s) + integer function number_of_rows_numeric(s) result(nrows) ! determine number or rows integer,intent(in)::s integer :: ios - real::r + real :: r + complex :: z rewind(s) - number_of_rows_numeric = 0 + nrows = 0 do read(s, *, iostat=ios) r if (ios /= 0) exit - number_of_rows_numeric = number_of_rows_numeric + 1 + nrows = nrows + 1 end do rewind(s) + ! If there are no rows of real numbers, it may be that they are complex + if( nrows == 0) then + do + read(s, *, iostat=ios) z + if (ios /= 0) exit + nrows = nrows + 1 + end do + rewind(s) + end if end function number_of_rows_numeric diff --git a/src/stdlib_experimental_io.md b/src/stdlib_experimental_io.md index 9ef005759..d90185209 100644 --- a/src/stdlib_experimental_io.md +++ b/src/stdlib_experimental_io.md @@ -20,7 +20,7 @@ Loads a rank-2 `array` from a text file. `filename`: Shall be a character expression containing the file name from which to load the rank-2 `array`. -`array`: Shall be an allocatable rank-2 array of type `real` or `integer`. +`array`: Shall be an allocatable rank-2 array of type `real`, `complex` or `integer`. ### Return value @@ -104,7 +104,7 @@ Saves a rank-2 `array` into a text file. `filename`: Shall be a character expression containing the name of the file that will contain the 2D `array`. -`array`: Shall be a rank-2 array of type `real` or `integer`. +`array`: Shall be a rank-2 array of type `real`, `complex` or `integer`. ### Output diff --git a/src/stdlib_experimental_optval.f90 b/src/stdlib_experimental_optval.f90 deleted file mode 100644 index c2f9a0f46..000000000 --- a/src/stdlib_experimental_optval.f90 +++ /dev/null @@ -1,153 +0,0 @@ -module stdlib_experimental_optval - !! - !! Provides a generic function `optval`, which can be used to - !! conveniently implement fallback values for optional arguments - !! to subprograms. If `x` is an `optional` parameter of a - !! subprogram, then the expression `optval(x, default)` inside that - !! subprogram evaluates to `x` if it is present, otherwise `default`. - !! - !! It is an error to call `optval` with a single actual argument. - !! - use stdlib_experimental_kinds, only: sp, dp, qp, int8, int16, int32, int64 - implicit none - - - private - public :: optval - - - interface optval - module procedure optval_sp - module procedure optval_dp - module procedure optval_qp - module procedure optval_int8 - module procedure optval_int16 - module procedure optval_int32 - module procedure optval_int64 - module procedure optval_logical - module procedure optval_character - ! TODO: complex kinds - ! TODO: differentiate ascii & ucs char kinds - end interface optval - - -contains - - - pure elemental function optval_sp(x, default) result(y) - real(sp), intent(in), optional :: x - real(sp), intent(in) :: default - real(sp) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_sp - - - pure elemental function optval_dp(x, default) result(y) - real(dp), intent(in), optional :: x - real(dp), intent(in) :: default - real(dp) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_dp - - - pure elemental function optval_qp(x, default) result(y) - real(qp), intent(in), optional :: x - real(qp), intent(in) :: default - real(qp) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_qp - - - pure elemental function optval_int8(x, default) result(y) - integer(int8), intent(in), optional :: x - integer(int8), intent(in) :: default - integer(int8) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_int8 - - - pure elemental function optval_int16(x, default) result(y) - integer(int16), intent(in), optional :: x - integer(int16), intent(in) :: default - integer(int16) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_int16 - - - pure elemental function optval_int32(x, default) result(y) - integer(int32), intent(in), optional :: x - integer(int32), intent(in) :: default - integer(int32) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_int32 - - - pure elemental function optval_int64(x, default) result(y) - integer(int64), intent(in), optional :: x - integer(int64), intent(in) :: default - integer(int64) :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_int64 - - - pure elemental function optval_logical(x, default) result(y) - logical, intent(in), optional :: x - logical, intent(in) :: default - logical :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_logical - - - pure function optval_character(x, default) result(y) - character(len=*), intent(in), optional :: x - character(len=*), intent(in) :: default - character(len=:), allocatable :: y - - if (present(x)) then - y = x - else - y = default - end if - end function optval_character - -end module stdlib_experimental_optval diff --git a/src/stdlib_experimental_optval.fypp b/src/stdlib_experimental_optval.fypp new file mode 100644 index 000000000..7c5977666 --- /dev/null +++ b/src/stdlib_experimental_optval.fypp @@ -0,0 +1,62 @@ +#:include "common.fypp" + +#:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + CMPLX_KINDS_TYPES + & + & [('l1','logical')] + +module stdlib_experimental_optval + !! + !! Provides a generic function `optval`, which can be used to + !! conveniently implement fallback values for optional arguments + !! to subprograms. If `x` is an `optional` parameter of a + !! subprogram, then the expression `optval(x, default)` inside that + !! subprogram evaluates to `x` if it is present, otherwise `default`. + !! + !! It is an error to call `optval` with a single actual argument. + !! + use stdlib_experimental_kinds, only: sp, dp, qp, int8, int16, int32, int64 + implicit none + + + private + public :: optval + + + interface optval + #:for k1, t1 in KINDS_TYPES + module procedure optval_${t1[0]}$${k1}$ + #:endfor + module procedure optval_character + ! TODO: differentiate ascii & ucs char kinds + end interface optval + + +contains + + #:for k1, t1 in KINDS_TYPES + pure elemental function optval_${t1[0]}$${k1}$(x, default) result(y) + ${t1}$, intent(in), optional :: x + ${t1}$, intent(in) :: default + ${t1}$ :: y + + if (present(x)) then + y = x + else + y = default + end if + end function optval_${t1[0]}$${k1}$ + #:endfor + + ! Cannot be made elemental + pure function optval_character(x, default) result(y) + character(len=*), intent(in), optional :: x + character(len=*), intent(in) :: default + character(len=:), allocatable :: y + + if (present(x)) then + y = x + else + y = default + end if + end function optval_character + +end module stdlib_experimental_optval diff --git a/src/tests/io/array5.dat b/src/tests/io/array5.dat new file mode 100644 index 000000000..708698511 --- /dev/null +++ b/src/tests/io/array5.dat @@ -0,0 +1,2 @@ + (1.0000000000000000,0.0000000000000000) (3.0000000000000000,0.0000000000000000) (5.0000000000000000,0.0000000000000000) + (2.0000000000000000,0.0000000000000000) (4.0000000000000000,0.0000000000000000) (6.0000000000000000,0.0000000000000000) diff --git a/src/tests/io/test_loadtxt.f90 b/src/tests/io/test_loadtxt.f90 index 32d152223..3b16cc20d 100644 --- a/src/tests/io/test_loadtxt.f90 +++ b/src/tests/io/test_loadtxt.f90 @@ -7,6 +7,7 @@ program test_loadtxt integer(int32), allocatable :: i(:, :) real(sp), allocatable :: s(:, :) real(dp), allocatable :: d(:, :) +complex(dp), allocatable :: z(:, :) call loadtxt("array1.dat", i) call print_array(i) @@ -26,6 +27,9 @@ program test_loadtxt call loadtxt("array4.dat", d) call print_array(d) +call loadtxt("array5.dat", z) +call print_array(z) + contains subroutine print_array(a) @@ -46,6 +50,10 @@ subroutine print_array(a) do i = 1, size(a, 1) print *, a(i, :) end do + type is(complex(dp)) + do i = 1, size(a, 1) + print *, a(i, :) + end do class default call error_stop('The proposed type is not supported') end select diff --git a/src/tests/io/test_savetxt.f90 b/src/tests/io/test_savetxt.f90 index 288a7b1aa..8b7d13fcc 100644 --- a/src/tests/io/test_savetxt.f90 +++ b/src/tests/io/test_savetxt.f90 @@ -8,9 +8,11 @@ program test_savetxt outpath = get_outpath() // "/tmp.dat" -call test_int32(outpath) -call test_sp(outpath) -call test_dp(outpath) +call test_iint32(outpath) +call test_rsp(outpath) +call test_rdp(outpath) +call test_csp(outpath) +call test_cdp(outpath) contains @@ -27,7 +29,7 @@ function get_outpath() result(outpath) endif end function get_outpath - subroutine test_int32(outpath) + subroutine test_iint32(outpath) character(*), intent(in) :: outpath integer(int32) :: d(3, 2), e(2, 3) integer(int32), allocatable :: d2(:, :) @@ -45,7 +47,7 @@ subroutine test_int32(outpath) end subroutine - subroutine test_sp(outpath) + subroutine test_rsp(outpath) character(*), intent(in) :: outpath real(sp) :: d(3, 2), e(2, 3) real(sp), allocatable :: d2(:, :) @@ -60,10 +62,10 @@ subroutine test_sp(outpath) call loadtxt(outpath, d2) call assert(all(shape(d2) == [2, 3])) call assert(all(abs(e-d2) < epsilon(1._sp))) - end subroutine + end subroutine test_rsp - subroutine test_dp(outpath) + subroutine test_rdp(outpath) character(*), intent(in) :: outpath real(dp) :: d(3, 2), e(2, 3) real(dp), allocatable :: d2(:, :) @@ -78,6 +80,40 @@ subroutine test_dp(outpath) call loadtxt(outpath, d2) call assert(all(shape(d2) == [2, 3])) call assert(all(abs(e-d2) < epsilon(1._dp))) - end subroutine + end subroutine test_rdp + + subroutine test_csp(outpath) + character(*), intent(in) :: outpath + complex(sp) :: d(3, 2), e(2, 3) + complex(sp), allocatable :: d2(:, :) + d = cmplx(1, 1)* reshape([1, 2, 3, 4, 5, 6], [3, 2]) + call savetxt(outpath, d) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [3, 2])) + call assert(all(abs(d-d2) < epsilon(1._sp))) + + e = cmplx(1, 1)* reshape([1, 2, 3, 4, 5, 6], [2, 3]) + call savetxt(outpath, e) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [2, 3])) + call assert(all(abs(e-d2) < epsilon(1._sp))) + end subroutine test_csp + + subroutine test_cdp(outpath) + character(*), intent(in) :: outpath + complex(dp) :: d(3, 2), e(2, 3) + complex(dp), allocatable :: d2(:, :) + d = cmplx(1._dp, 1._dp)* reshape([1, 2, 3, 4, 5, 6], [3, 2]) + call savetxt(outpath, d) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [3, 2])) + call assert(all(abs(d-d2) < epsilon(1._dp))) + + e = cmplx(1, 1)* reshape([1, 2, 3, 4, 5, 6], [2, 3]) + call savetxt(outpath, e) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [2, 3])) + call assert(all(abs(e-d2) < epsilon(1._dp))) + end subroutine test_cdp -end program +end program test_savetxt diff --git a/src/tests/io/test_savetxt_qp.f90 b/src/tests/io/test_savetxt_qp.f90 index 69a973e00..8ebb7151a 100644 --- a/src/tests/io/test_savetxt_qp.f90 +++ b/src/tests/io/test_savetxt_qp.f90 @@ -8,7 +8,8 @@ program test_savetxt_qp outpath = get_outpath() // "/tmp_qp.dat" -call test_qp(outpath) +call test_rqp(outpath) +call test_cqp(outpath) contains @@ -25,7 +26,7 @@ function get_outpath() result(outpath) endif end function get_outpath - subroutine test_qp(outpath) + subroutine test_rqp(outpath) character(*), intent(in) :: outpath real(qp) :: d(3, 2), e(2, 3) real(qp), allocatable :: d2(:, :) @@ -40,6 +41,23 @@ subroutine test_qp(outpath) call loadtxt(outpath, d2) call assert(all(shape(d2) == [2, 3])) call assert(all(abs(e-d2) < epsilon(1._qp))) - end subroutine + end subroutine test_rqp -end program + subroutine test_cqp(outpath) + character(*), intent(in) :: outpath + complex(qp) :: d(3, 2), e(2, 3) + complex(qp), allocatable :: d2(:, :) + d = reshape([1, 2, 3, 4, 5, 6], [3, 2]) + call savetxt(outpath, d) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [3, 2])) + call assert(all(abs(d-d2) < epsilon(1._qp))) + + e = reshape([1, 2, 3, 4, 5, 6], [2, 3]) + call savetxt(outpath, e) + call loadtxt(outpath, d2) + call assert(all(shape(d2) == [2, 3])) + call assert(all(abs(e-d2) < epsilon(1._qp))) + end subroutine test_cqp + +end program test_savetxt_qp diff --git a/src/tests/optval/test_optval.f90 b/src/tests/optval/test_optval.f90 index 482e55ac6..00a40a8fa 100644 --- a/src/tests/optval/test_optval.f90 +++ b/src/tests/optval/test_optval.f90 @@ -7,36 +7,44 @@ program test_optval implicit none - call test_optval_sp - call test_optval_dp - call test_optval_qp + call test_optval_rsp + call test_optval_rdp + call test_optval_rqp - call test_optval_int8 - call test_optval_int16 - call test_optval_int32 - call test_optval_int64 + call test_optval_csp + call test_optval_cdp + call test_optval_cqp + + call test_optval_iint8 + call test_optval_iint16 + call test_optval_iint32 + call test_optval_iint64 call test_optval_logical call test_optval_character - call test_optval_sp_arr - call test_optval_dp_arr - call test_optval_qp_arr + call test_optval_rsp_arr + call test_optval_rdp_arr + call test_optval_rqp_arr + + call test_optval_csp_arr + call test_optval_cdp_arr + call test_optval_cqp_arr - call test_optval_int8_arr - call test_optval_int16_arr - call test_optval_int32_arr - call test_optval_int64_arr + call test_optval_iint8_arr + call test_optval_iint16_arr + call test_optval_iint32_arr + call test_optval_iint64_arr contains - subroutine test_optval_sp - print *, "test_optval_sp" + subroutine test_optval_rsp + print *, "test_optval_rsp" call assert(foo_sp(1.0_sp) == 1.0_sp) call assert(foo_sp() == 2.0_sp) - end subroutine test_optval_sp + end subroutine test_optval_rsp function foo_sp(x) result(z) @@ -46,11 +54,11 @@ function foo_sp(x) result(z) endfunction foo_sp - subroutine test_optval_dp - print *, "test_optval_dp" + subroutine test_optval_rdp + print *, "test_optval_rdp" call assert(foo_dp(1.0_dp) == 1.0_dp) call assert(foo_dp() == 2.0_dp) - end subroutine test_optval_dp + end subroutine test_optval_rdp function foo_dp(x) result(z) @@ -60,11 +68,11 @@ function foo_dp(x) result(z) endfunction foo_dp - subroutine test_optval_qp - print *, "test_optval_qp" + subroutine test_optval_rqp + print *, "test_optval_rqp" call assert(foo_qp(1.0_qp) == 1.0_qp) call assert(foo_qp() == 2.0_qp) - end subroutine test_optval_qp + end subroutine test_optval_rqp function foo_qp(x) result(z) @@ -74,11 +82,56 @@ function foo_qp(x) result(z) endfunction foo_qp - subroutine test_optval_int8 - print *, "test_optval_int8" + subroutine test_optval_csp + complex(sp) :: z1 + print *, "test_optval_csp" + z1 = cmplx(1.0_sp, 2.0_sp, kind=sp) + call assert(foo_csp(z1) == z1) + call assert(foo_csp() == z1) + end subroutine test_optval_csp + + function foo_csp(x) result(z) + complex(sp), intent(in), optional :: x + complex(sp) :: z + z = optval(x, cmplx(1.0_sp, 2.0_sp, kind=sp)) + endfunction foo_csp + + + subroutine test_optval_cdp + complex(dp) :: z1 + print *, "test_optval_cdp" + z1 = cmplx(1.0_dp, 2.0_dp) + call assert(foo_cdp(z1) == z1) + call assert(foo_cdp() == z1) + end subroutine test_optval_cdp + + function foo_cdp(x) result(z) + complex(dp), intent(in), optional :: x + complex(dp) :: z + z = optval(x, cmplx(1.0_dp, 2.0_dp, kind=dp)) + endfunction foo_cdp + + + subroutine test_optval_cqp + complex(qp) :: z1 + print *, "test_optval_cqp" + z1 = cmplx(1.0_qp, 2.0_qp, kind=qp) + call assert(foo_cqp(z1) == z1) + call assert(foo_cqp() == z1) + end subroutine test_optval_cqp + + function foo_cqp(x) result(z) + complex(qp), intent(in), optional :: x + complex(qp) :: z + z = optval(x, cmplx(1.0_qp, 2.0_qp, kind=qp)) + endfunction foo_cqp + + + subroutine test_optval_iint8 + print *, "test_optval_iint8" call assert(foo_int8(1_int8) == 1_int8) call assert(foo_int8() == 2_int8) - end subroutine test_optval_int8 + end subroutine test_optval_iint8 function foo_int8(x) result(z) @@ -88,11 +141,11 @@ function foo_int8(x) result(z) endfunction foo_int8 - subroutine test_optval_int16 - print *, "test_optval_int16" + subroutine test_optval_iint16 + print *, "test_optval_iint16" call assert(foo_int16(1_int16) == 1_int16) call assert(foo_int16() == 2_int16) - end subroutine test_optval_int16 + end subroutine test_optval_iint16 function foo_int16(x) result(z) @@ -102,11 +155,11 @@ function foo_int16(x) result(z) endfunction foo_int16 - subroutine test_optval_int32 - print *, "test_optval_int32" + subroutine test_optval_iint32 + print *, "test_optval_iint32" call assert(foo_int32(1_int32) == 1_int32) call assert(foo_int32() == 2_int32) - end subroutine test_optval_int32 + end subroutine test_optval_iint32 function foo_int32(x) result(z) @@ -116,11 +169,11 @@ function foo_int32(x) result(z) endfunction foo_int32 - subroutine test_optval_int64 + subroutine test_optval_iint64 print *, "test_optval_int64" call assert(foo_int64(1_int64) == 1_int64) call assert(foo_int64() == 2_int64) - end subroutine test_optval_int64 + end subroutine test_optval_iint64 function foo_int64(x) result(z) @@ -158,11 +211,11 @@ function foo_character(x) result(z) endfunction foo_character - subroutine test_optval_sp_arr - print *, "test_optval_sp_arr" + subroutine test_optval_rsp_arr + print *, "test_optval_rsp_arr" call assert(all(foo_sp_arr([1.0_sp, -1.0_sp]) == [1.0_sp, -1.0_sp])) call assert(all(foo_sp_arr() == [2.0_sp, -2.0_sp])) - end subroutine test_optval_sp_arr + end subroutine test_optval_rsp_arr function foo_sp_arr(x) result(z) @@ -172,11 +225,11 @@ function foo_sp_arr(x) result(z) end function foo_sp_arr - subroutine test_optval_dp_arr - print *, "test_optval_dp_arr" + subroutine test_optval_rdp_arr + print *, "test_optval_rdp_arr" call assert(all(foo_dp_arr([1.0_dp, -1.0_dp]) == [1.0_dp, -1.0_dp])) call assert(all(foo_dp_arr() == [2.0_dp, -2.0_dp])) - end subroutine test_optval_dp_arr + end subroutine test_optval_rdp_arr function foo_dp_arr(x) result(z) @@ -186,11 +239,11 @@ function foo_dp_arr(x) result(z) end function foo_dp_arr - subroutine test_optval_qp_arr + subroutine test_optval_rqp_arr print *, "test_optval_qp_arr" call assert(all(foo_qp_arr([1.0_qp, -1.0_qp]) == [1.0_qp, -1.0_qp])) call assert(all(foo_qp_arr() == [2.0_qp, -2.0_qp])) - end subroutine test_optval_qp_arr + end subroutine test_optval_rqp_arr function foo_qp_arr(x) result(z) @@ -200,11 +253,62 @@ function foo_qp_arr(x) result(z) end function foo_qp_arr - subroutine test_optval_int8_arr + subroutine test_optval_csp_arr + complex(sp), dimension(2) :: z1, z2 + print *, "test_optval_csp_arr" + z1 = cmplx(1.0_sp, 2.0_sp, kind=sp)*[1.0_sp, -1.0_sp] + z2 = cmplx(2.0_sp, 2.0_sp, kind=sp)*[1.0_sp, -1.0_sp] + call assert(all(foo_csp_arr(z1) == z1)) + call assert(all(foo_csp_arr() == z2)) + end subroutine test_optval_csp_arr + + + function foo_csp_arr(x) result(z) + complex(sp), dimension(2), intent(in), optional :: x + complex(sp), dimension(2) :: z + z = optval(x, cmplx(2.0_sp, 2.0_sp, kind=sp)*[1.0_sp, -1.0_sp]) + end function foo_csp_arr + + + subroutine test_optval_cdp_arr + complex(dp), dimension(2) :: z1, z2 + print *, "test_optval_cdp_arr" + z1 = cmplx(1.0_dp, 2.0_dp, kind=dp)*[1.0_dp, -1.0_dp] + z2 = cmplx(2.0_dp, 2.0_dp, kind=dp)*[1.0_dp, -1.0_dp] + call assert(all(foo_cdp_arr(z1) == z1)) + call assert(all(foo_cdp_arr() == z2)) + end subroutine test_optval_cdp_arr + + + function foo_cdp_arr(x) result(z) + complex(dp), dimension(2), intent(in), optional :: x + complex(dp), dimension(2) :: z + z = optval(x, cmplx(2.0_dp, 2.0_dp, kind=dp)*[1.0_dp, -1.0_dp]) + end function foo_cdp_arr + + + subroutine test_optval_cqp_arr + complex(qp), dimension(2) :: z1, z2 + print *, "test_optval_cqp_arr" + z1 = cmplx(1.0_qp, 2.0_qp, kind=qp)*[1.0_qp, -1.0_qp] + z2 = cmplx(2.0_qp, 2.0_qp, kind=qp)*[1.0_qp, -1.0_qp] + call assert(all(foo_cqp_arr(z1) == z1)) + call assert(all(foo_cqp_arr() == z2)) + end subroutine test_optval_cqp_arr + + + function foo_cqp_arr(x) result(z) + complex(qp), dimension(2), intent(in), optional :: x + complex(qp), dimension(2) :: z + z = optval(x, cmplx(2.0_qp, 2.0_qp, kind=qp)*[1.0_qp, -1.0_qp]) + end function foo_cqp_arr + + + subroutine test_optval_iint8_arr print *, "test_optval_int8_arr" call assert(all(foo_int8_arr([1_int8, -1_int8]) == [1_int8, -1_int8])) call assert(all(foo_int8_arr() == [2_int8, -2_int8])) - end subroutine test_optval_int8_arr + end subroutine test_optval_iint8_arr function foo_int8_arr(x) result(z) @@ -214,11 +318,11 @@ function foo_int8_arr(x) result(z) end function foo_int8_arr - subroutine test_optval_int16_arr + subroutine test_optval_iint16_arr print *, "test_optval_int16_arr" call assert(all(foo_int16_arr([1_int16, -1_int16]) == [1_int16, -1_int16])) call assert(all(foo_int16_arr() == [2_int16, -2_int16])) - end subroutine test_optval_int16_arr + end subroutine test_optval_iint16_arr function foo_int16_arr(x) result(z) @@ -228,11 +332,11 @@ function foo_int16_arr(x) result(z) end function foo_int16_arr - subroutine test_optval_int32_arr + subroutine test_optval_iint32_arr print *, "test_optval_int32_arr" call assert(all(foo_int32_arr([1_int32, -1_int32]) == [1_int32, -1_int32])) call assert(all(foo_int32_arr() == [2_int32, -2_int32])) - end subroutine test_optval_int32_arr + end subroutine test_optval_iint32_arr function foo_int32_arr(x) result(z) @@ -242,11 +346,11 @@ function foo_int32_arr(x) result(z) end function foo_int32_arr - subroutine test_optval_int64_arr + subroutine test_optval_iint64_arr print *, "test_optval_int64_arr" call assert(all(foo_int64_arr([1_int64, -1_int64]) == [1_int64, -1_int64])) call assert(all(foo_int64_arr() == [2_int64, -2_int64])) - end subroutine test_optval_int64_arr + end subroutine test_optval_iint64_arr function foo_int64_arr(x) result(z)