mgaitan / fortran_magic

An extension for IPython/Jupyter that helps to use Fortran in your interactive session.
BSD 3-Clause "New" or "Revised" License
117 stars 32 forks source link

intent(hide) #12

Closed arogozhnikov closed 8 years ago

arogozhnikov commented 9 years ago

Hi. First of all, thanks for this magic. I'm new to fortran, so it is an awesome ability for me to try using fortran from IPython.

Unfortunately, I'm not able to use intent(hide) variables for sizes, while it seems important. It is code from official f2py guide:

subroutine zadd(a,b,c,n) ! in :add:add.f
   double complex dimension(n) :: a
   double complex dimension(n) :: b
   double complex intent(out),dimension(n) :: c
   integer intent(hide),depend(a) :: n=len(a)
   c = a + b    ! I want to use vector operations, so fortran 90 or later.
end subroutine zadd

And it fails compiling with very long log, important part is

    double complex dimension(n) :: a
                              1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:4:30:

    double complex dimension(n) :: b
                              1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:5:42:

    double complex intent(out),dimension(n) :: c
                                          1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:6:33:

    integer intent(hide),depend(a) :: n=len(a)
                                 1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:3:30:

    double complex dimension(n) :: a
                              1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:4:30:

    double complex dimension(n) :: b
                              1
Error: Syntax error in data declaration at (1)
/Users/axelr/.ipython/fortran/_fortran_magic_d1fc3ba820eff5c66eb0e6000c364ed6.f90:5:42:

Do you know a convenient way to work with arrays of dynamic size? Or there are some flags I should add?

Thanks in advance.

arogozhnikov commented 8 years ago

This is workaround I am using:

subroutine zadd(a,b,c,n)
   real, intent(in) :: a(:), b(:)
   real, intent(out) :: c(size(a, 1))
   c(:) = a(:) + b (:)
end subroutine

But if someone knows how to do it with intend(hide), I'd be happy to know.