ecmwf-ifs / loki

Freely programmable source-to-source translation for Fortran
https://sites.ecmwf.int/docs/loki/
Apache License 2.0
22 stars 11 forks source link

bug with assumed-size #333

Open ecossevin opened 1 month ago

ecossevin commented 1 month ago

sub.F90 :

SUBROUTINE TOTO(KPROMA, POUT1)

IMPLICIT NONE
INTEGER, INTENT (IN)::KPROMA
REAL, INTENT (OUT)::POUT1 (KPROMA,*)

END SUBROUTINE TOTO

test.py :

from loki import *
import sys

file_name = "sub.F90"
source=Sourcefile.from_file(file_name)
src_name = "TOTO"
routine=source[src_name]
print(fgen(routine))

test.py (fgen) returns wrong dimensions for POUT1: REAL, INTENT(OUT) :: POUT1((KPROMA,):)

Thanks in advance for your help.

reuterbal commented 1 week ago

Thanks, we seem to indeed not have a representation of assumed size dimensions. Here's a pytest reproducing the issue and capturing all relevant cases that seem to be allowed in Fortran:


@pytest.mark.parametrize('frontend', available_frontends())
def test_array_assumed_size(frontend):
    fcode = """
SUBROUTINE TOTO(KPROMA, A, B, C, POUT1)
IMPLICIT NONE
INTEGER, INTENT (IN)    :: KPROMA
INTEGER, INTENT (INOUT) :: A(5, *), B(*), C(0:1, 2:*)
REAL   , INTENT (OUT)   :: POUT1 (KPROMA, *)
    SUBROUTINE PULLDOWN ( A, B, C )
END SUBROUTINE TOTO
    """.strip()
    routine = Subroutine.from_source(fcode, frontend=frontend)

The precise format of representing this needs to be discussed, though.