Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatched dimensinons and type #26

Open
mankoff opened this issue Jul 26, 2023 · 1 comment
Open

Mismatched dimensinons and type #26

mankoff opened this issue Jul 26, 2023 · 1 comment

Comments

@mankoff
Copy link

mankoff commented Jul 26, 2023

I'm trying to pass an array between Fortran and Python but the dimensions and type are not matched. In Fortran I have

(gdb) ptype tgrnd
type = real(kind=8) (2,72,0:47)

And I pass it with your library with:

call set_state("tg", tgrnd)
call call_function("foo", "bar")

And in Python the type and dimensions are:

def bar(STATE):
    tg = STATE.get("tg", np.nan)
    print("LIME_py0:", tg.shape)
    print("LIME_py0:", type(tg))
    print("LIME_py0:", type(tg[0,0,0]))

Which outputs

LIME_py0: (25, 72, 2)
LIME_py0: <class 'numpy.ndarray'>
LIME_py0: <class 'numpy.float64'>

The suspicious part above is the dimensions are 0:47 and not 48. This array, tgrnd, is created with the following statement:

      REAL*8, DIMENSION(2,GRID%I_STRT_HALO:GRID%I_STOP_HALO,
     &                    GRID%J_STRT_HALO:GRID%J_STOP_HALO) ::
     &     TGRND,TGRN2,TGR4,E1 ! 2 for ocean,seaice

I have a work-around: I can create a new array with explicit dimensions, then copy the values to that, e.g.,

real*8, dimension(2,72,48) :: LIME_T
LIME_T = tgrnd

And then if I pass LIME_T to set_state, everything works. I'm not yet sure how to fix this issue, but wanted to raise it.

@nbren12
Copy link
Owner

nbren12 commented Jul 26, 2023

I wouldn't be surprised if there is some error related to using lbound!=1. This is the relevant portion of the code:

real(c_double) :: t_(size(t, 1), size(t, 2))
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants