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

  • Fortran
  • Thread starter natski
  • Start date
  • Tags
    Fortran
In summary, the conversation discusses how to pass a single column or row of an array into a subroutine using the f90 programming language. It is important to make sure the variable in the subroutine has the correct shape and there are various methods for sizing the array in the subroutine.
  • #1
natski
267
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
  • #2
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.
 

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

1. What are Fortran subarrays?

Fortran subarrays are a subset of an array, which is a data structure that stores a collection of values. Subarrays allow for a more efficient way to access and manipulate data within an array.

2. How are subarrays created in Fortran?

Subarrays are created by specifying a range of indices within an existing array. This range can be specified using colon (:) notation or by using the reshape function.

3. What are the advantages of using subarrays in Fortran?

Using subarrays in Fortran can lead to more efficient code, as it allows for easier manipulation of data within an array. It also allows for easier implementation of algorithms, as it provides a more intuitive way to access and modify data.

4. Can subarrays be multidimensional in Fortran?

Yes, subarrays can be multidimensional in Fortran. This means that a subarray can be created from a specific range of values in one or more dimensions of an array.

5. Are subarrays mutable in Fortran?

Yes, subarrays are mutable in Fortran. This means that the values within a subarray can be changed or modified, just like the values within an array. However, the size and shape of a subarray cannot be changed once it is created.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
4
Views
750
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
5
Views
7K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
4
Views
7K
Back
Top