Using Fortran Subarrays in f90: Passing Single Columns/Rows into a Subroutine

  • Context: Fortran 
  • Thread starter Thread starter natski
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
natski
Messages
262
Reaction score
2
Dear all,

I am using f90 and trying to pass only one column/row of an array into a subroutine. So I want something like...

call test(x(1,:),...)

If "test" defines the first entry as a vector, will this work?

Natski
 
Physics news on Phys.org
It will work, so long as the variable in the subroutine has the proper shape. Also, you're syntax is a little wrong, here's what it would look like:
Code:
DIMENSION(10,10,10) :: x

CALL test( x(:,1,1) )
END PROGRAM

SUBROUTINE test
DIMENSION(:),INTENT(whatever) :: x
...
There are a few different methods to sizing the array in the subroutine. Often times we'll not specify the size and let the compiler use an "assumed" array sizing.