Skip to content

Commit 8530358

Browse files
committed
modify optional argument; move to the top use statements in stdlib_math_meshgrid.fypp
1 parent b7248d9 commit 8530358

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

doc/specs/stdlib_math.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ Shall be arrays of type `real` or `integer` of adequate shape:
602602
These argument are `intent(out)`.
603603

604604
`indexing`: the selected indexing.
605-
Shall be a `character(len=2)` equal to `"xy"` for Cartesian indexing (default), or `"ij"` for matrix indexing.
606-
This argument is `intent(in)` and `optional`, and is equal to `"xy"` by default.
605+
Shall be an `integer` equal to `stdlib_meshgrid_xy` for Cartesian indexing (default), or `stdlib_meshgrid_ij` for matrix indexing. `stdlib_meshgrid_xy` and `stdlib_meshgrid_ij` are public constants defined in the module.
606+
This argument is `intent(in)` and `optional`, and is equal to `stdlib_meshgrid_xy` by default.
607607

608608
#### Example
609609

example/math/example_meshgrid.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
program example_meshgrid
22

3-
use stdlib_math, only: meshgrid, linspace
3+
use stdlib_math, only: meshgrid, linspace, stdlib_meshgrid_ij
44
use stdlib_kinds, only: sp
55

66
implicit none
@@ -19,7 +19,7 @@ program example_meshgrid
1919
print *, "ym_cart = "
2020
call print_2d_array(ym_cart)
2121

22-
call meshgrid(x, y, xm_mat, ym_mat, indexing="ij")
22+
call meshgrid(x, y, xm_mat, ym_mat, indexing=stdlib_meshgrid_ij)
2323
print *, "xm_mat = "
2424
call print_2d_array(xm_mat)
2525
print *, "ym_mat = "

src/stdlib_math.fypp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module stdlib_math
1414
public :: EULERS_NUMBER_QP
1515
#:endif
1616
public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH
17+
public :: stdlib_meshgrid_ij, stdlib_meshgrid_xy
1718
public :: arange, arg, argd, argpi, is_close, all_close, diff, meshgrid
1819

1920
integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100
@@ -32,6 +33,9 @@ module stdlib_math
3233
real(kind=${k1}$), parameter :: PI_${k1}$ = acos(-1.0_${k1}$)
3334
#:endfor
3435

36+
!> Values for optional argument `indexing` of `meshgrid`
37+
integer, parameter :: stdlib_meshgrid_xy = 0, stdlib_meshgrid_ij = 1
38+
3539
interface clip
3640
#:for k1, t1 in IR_KINDS_TYPES
3741
module procedure clip_${k1}$
@@ -401,7 +405,7 @@ module stdlib_math
401405
${t1}$, intent(in) :: x${i}$(:)
402406
${t1}$, intent(out) :: xm${i}$ ${ranksuffix(rank)}$
403407
#:endfor
404-
character(len=2), intent(in), optional :: indexing
408+
integer, intent(in), optional :: indexing
405409
end subroutine ${RName}$
406410
#:endfor
407411
#:endfor

src/stdlib_math_meshgrid.fypp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
submodule(stdlib_math) stdlib_math_meshgrid
1919

20+
use stdlib_error, only: error_stop
21+
2022
contains
2123

2224
#:for k1, t1 in IR_KINDS_TYPES
@@ -30,15 +32,13 @@ contains
3032
#:endif
3133
#: set RName = rname("meshgrid", rank, t1, k1)
3234
module procedure ${RName}$
33-
use stdlib_optval, only: optval
34-
use stdlib_error, only: error_stop
3535

3636
integer :: ${"".join(f"i{j}," for j in range(1, rank + 1)).removesuffix(",")}$
3737

38-
select case (optval(indexing, "xy"))
39-
case ("xy")
38+
select case (optval(indexing, stdlib_meshgrid_xy))
39+
case (stdlib_meshgrid_xy)
4040
$:meshgrid_loop(XY_INDICES)
41-
case ("ij")
41+
case (stdlib_meshgrid_ij)
4242
$:meshgrid_loop(IJ_INDICES)
4343
case default
4444
call error_stop("ERROR (meshgrid): unexpected indexing.")

test/math/test_meshgrid.fypp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
#:def OPTIONAL_PART_IN_SIGNATURE(indexing)
99
#:if indexing in ("xy", "ij")
10-
${f', "{indexing}"'}$
10+
${f', stdlib_meshgrid_{indexing}'}$
1111
#:endif
1212
#:enddef
1313

1414
module test_meshgrid
1515
use testdrive, only : new_unittest, unittest_type, error_type, check
16-
use stdlib_math, only: meshgrid
16+
use stdlib_math, only: meshgrid, stdlib_meshgrid_ij, stdlib_meshgrid_xy
1717
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
1818
implicit none
1919

0 commit comments

Comments
 (0)