예제 #1
0
def test_parse_many():
    buf = '''\
subroutine subr1(a, b, c)
implicit none
integer, intent(in) :: a
complex :: b
double precision, intent(out) :: c

c = a + aimag(b)

end subroutine subr1


function func1(a, b, c)
implicit none
integer, intent(in) :: a
real :: b
complex, intent(in) :: c
double precision :: func1

func1 = a + aimag(c) - b

end function func1
'''
    subr, func = fp.generate_ast([buf])
    eq_(subr.name, 'subr1')
    eq_(func.name, 'func1')
    eq_([arg.name for arg in subr.args], ['a', 'b', 'c'])
    eq_([arg.dtype for arg in subr.args], [pyf.default_integer,
                                           pyf.default_complex,
                                           pyf.default_dbl])
예제 #2
0
def test_parse_many():
    buf = '''\
subroutine subr1(a, b, c)
implicit none
integer, intent(in) :: a
complex :: b
double precision, intent(out) :: c

c = a + aimag(b)

end subroutine subr1


function func1(a, b, c)
implicit none
integer, intent(in) :: a
real :: b
complex, intent(in) :: c
double precision :: func1

func1 = a + aimag(c) - b

end function func1
'''
    subr, func = fp.generate_ast([buf])
    eq_(subr.name, 'subr1')
    eq_(func.name, 'func1')
    eq_([arg.name for arg in subr.args], ['a', 'b', 'c'])
    eq_([arg.dtype for arg in subr.args],
        [pyf.default_integer, pyf.default_complex, pyf.default_dbl])
예제 #3
0
파일: main.py 프로젝트: certik/fwrap
def parse(source_files):
    r"""Parse fortran code returning parse tree

    :Input:
     - *source_files* - (list) List of valid source files
    """
    from fwrap import fwrap_parse
    ast = fwrap_parse.generate_ast(source_files)

    return ast
예제 #4
0
파일: fwrapper.py 프로젝트: wilsonify/fwrap
def parse(source_files):
    r"""Parse fortran code returning parse tree

    :Input:
     - *source_files* - (list) List of valid source files
    """
    from fwrap import fwrap_parse
    ast = fwrap_parse.generate_ast(source_files)

    return ast
예제 #5
0
def test_parse_kind_args():
    fcode = '''\
function int_args_func(a,b,c,d)
      integer(kind=8) :: int_args_func
      integer(kind=1), intent(in) :: a
      integer(kind=2), intent(in) :: b
      integer(kind=4), intent(in) :: c
      integer(kind=8), intent(out) :: d

      d = a + b + c
      int_args_func = 10

end function int_args_func
'''
    func = fp.generate_ast([fcode])[0]
    eq_([arg.dtype.odecl for arg in func.args],
        ["integer(kind=%d)" % i for i in (1, 2, 4, 8)])
예제 #6
0
def test_parse_kind_args():
    fcode = '''\
function int_args_func(a,b,c,d)
      integer(kind=8) :: int_args_func
      integer(kind=1), intent(in) :: a
      integer(kind=2), intent(in) :: b
      integer(kind=4), intent(in) :: c
      integer(kind=8), intent(out) :: d

      d = a + b + c
      int_args_func = 10

end function int_args_func
'''
    func = fp.generate_ast([fcode])[0]
    eq_([arg.dtype.odecl
            for arg in func.args],
        ["integer(kind=%d)" % i
            for i in (1,2,4,8)])
예제 #7
0
def test_parse_array_args():
    buf = '''\
      SUBROUTINE DGESDD( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK,
     $                   LWORK, IWORK, INFO )
*
*  -- LAPACK driver routine (version 3.2.1)                                  --
*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*     March 2009
*
*     .. Scalar Arguments ..
      CHARACTER          JOBZ
      INTEGER            INFO, LDA, LDU, LDVT, LWORK, M, N
*     ..
*     .. Array Arguments ..
      INTEGER            IWORK( * )
      DOUBLE PRECISION   A( LDA, * ), S( * ), U( LDU, * ),
     $                   VT( LDVT, * ), WORK( * )
      END SUBROUTINE DGESDD'''
    subr = fp.generate_ast([buf])[0]
    eq_(subr.name, 'dgesdd')
    eq_([arg.name for arg in subr.args],
        "jobz m n a lda s u ldu vt ldvt work lwork iwork info".split())
예제 #8
0
def test_parse_array_args():
    buf = '''\
      SUBROUTINE DGESDD( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK,
     $                   LWORK, IWORK, INFO )
*
*  -- LAPACK driver routine (version 3.2.1)                                  --
*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*     March 2009
*
*     .. Scalar Arguments ..
      CHARACTER          JOBZ
      INTEGER            INFO, LDA, LDU, LDVT, LWORK, M, N
*     ..
*     .. Array Arguments ..
      INTEGER            IWORK( * )
      DOUBLE PRECISION   A( LDA, * ), S( * ), U( LDU, * ),
     $                   VT( LDVT, * ), WORK( * )
      END SUBROUTINE DGESDD'''
    subr = fp.generate_ast([buf])[0]
    eq_(subr.name, 'dgesdd')
    eq_([arg.name for arg in subr.args],
        "jobz m n a lda s u ldu vt ldvt work lwork iwork info".split())