-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
|
||
! SPDX-License-Identifier: GPL-2.0+ | ||
|
||
module gh56 | ||
|
||
use iso_fortran_env, only: output_unit, real128 | ||
|
||
implicit none | ||
|
||
! Parameters | ||
integer, parameter :: dp = selected_real_kind(p=15) | ||
integer, parameter :: qp = selected_real_kind(p=30) | ||
integer, parameter :: lp = selected_int_kind(16) | ||
|
||
|
||
public :: get_array, print3, my_t | ||
|
||
type my_t | ||
real, allocatable :: d(:) | ||
integer :: n | ||
end type | ||
|
||
contains | ||
|
||
function get_array(N) result(retval) | ||
type(my_t) :: retval | ||
integer, intent(in) :: N | ||
integer :: i | ||
|
||
allocate( retval%d(N) ) | ||
retval%n = N | ||
|
||
! substitute with real data | ||
do i=1,N | ||
retval% d(i) = i | ||
end do | ||
end function | ||
|
||
subroutine print3(x) | ||
type(my_t), intent(in) :: x | ||
print *, x%d(:3) | ||
end subroutine | ||
|
||
|
||
|
||
end module gh56 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# SPDX-License-Identifier: GPL-2.0+ | ||
|
||
import os, sys | ||
import ctypes | ||
from pprint import pprint | ||
|
||
os.environ["_GFORT2PY_TEST_FLAG"] = "1" | ||
|
||
import numpy as np | ||
import gfort2py as gf | ||
|
||
import pytest | ||
|
||
SO = f"./tests/gh56.{gf.lib_ext()}" | ||
MOD = "./tests/gh56.mod" | ||
|
||
x = gf.fFort(SO, MOD) | ||
|
||
|
||
@pytest.mark.skip("Not fixed yet") | ||
class Testgh56Methods: | ||
def test_gh56(self, capfd): | ||
y1 = x.get_array(10).result | ||
|
||
y2 = x.get_array(5).result | ||
|
||
assert len(y1["d"]) == 10 | ||
assert len(y2["d"]) == 5 | ||
|
||
assert y1["d"] == np.array( | ||
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], dtype=np.float32 | ||
) | ||
|
||
assert y2["d"] == np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=np.float32) |