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
Click For Summary
SUMMARY

This discussion focuses on passing single columns or rows of arrays in Fortran 90 (f90) subroutines. The user seeks to call a subroutine with a specific array slice, and the consensus confirms that this is feasible if the subroutine's variable is correctly defined. An example provided demonstrates the syntax for passing a column of a 3D array using the CALL statement with an assumed-shape array in the subroutine. Proper array dimensioning is crucial for successful implementation.

PREREQUISITES
  • Understanding of Fortran 90 syntax and structure
  • Familiarity with subroutine definitions in Fortran
  • Knowledge of array dimensions and shapes in Fortran
  • Experience with assumed-shape arrays in Fortran
NEXT STEPS
  • Study Fortran 90 subroutine syntax and parameter passing
  • Learn about assumed-shape arrays in Fortran 90
  • Explore array slicing techniques in Fortran
  • Review best practices for array dimensioning in Fortran
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with array manipulations and subroutine implementations in scientific computing or numerical analysis.

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
 
Technology 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.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 4 ·
Replies
4
Views
3K