Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
7 Views

Passing Vector Segments to Assumed-sized Array

Jump to solution

Hello,

I working some inhereted code that uses assumed-size arrays. I haven't worked with assumed-size assays before (I'm under the impression that assumed-shaped are preferrable and assumed-size only exist for backward compatibility) and the way they are used doesn't seem to fit neatly into the documentation I have found online about assumed-size arrays. What seems strange to me is that the main program has one long vector and single elements of this vector are passed into assumed-size array interface parameters of a subroutine. The ones of these that are of the format a(*)  get created as vectors of length 1 but the ones that are of the form a(10,*) get created as arrays of shape (10,1). At least that is my understanding of how it behaves from reverse enginerring the  code. So my question is, have I understod correctly and can I rely one the code to consitently behave this way? To make the question clear here is a code snippet

    program test
    real ::X(100), y(5)
    
    call sub(x(1),x(10),x(50),y)
    
    contains
    subroutine sub(a,b,c)
    real:: a(*), b(10,*), c(*), d(*)
    
    end subroutine sub
    end program test

So in this example I a and c are of shape (1), b is of shape (10,1) and d is of shape (5). I've seen documentation explaining why d would be (5) but not confirming b should always be (10,1).

Thanks in advance

0 Kudos

Accepted Solutions
Highlighted
Retired Employee
7 Views

The extent of the last

Jump to solution

The extent of the last dimension of a,b,c and d are, technically, 100, 9, 51, 5, but there's no way to determine that in the program. Passing a single element to an assumed-size array is called "sequence association", and the dummy argument (a,b,c,d) is associated with the remainder of the extent of the actual argument. (b is a bit strange - as there is actually one more element left over. Your example would have been easier to explain if the subscripts were 11 and 51.)

In pre-F77 days, it was popular to declare dummy arrays with a last bound of 1, relying on the lack of bounds checking in most early compilers. F77 added assumed-size arrays which replace the (1) hack.

Here's what the standard says (8.5.8.5):

The size of an assumed-size array is determined as follows.
 • If the effective argument associated with the assumed-size dummy array is an array of any type other than default character, the size is that of the effective argument.
 • If the actual argument corresponding to the assumed-size dummy array is an array element of any type other than default character with a subscript order value of r (9.5.3.2) in an array of size x, the size of the dummy array is x − r + 1.
 • If the actual argument is a default character array, default character array element, or a default character array element substring (9.4.1), and if it begins at character storage unit t of an array with c character storage units, the size of the dummy array is MAX (INT ((c − t + 1)/e), 0), where e is the length of an element in the dummy character array.
 • If the actual argument is a default character scalar that is not an array element or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), where e is the length of an element in the dummy character array and l is the length of the actual argument.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran

View solution in original post

0 Kudos
3 Replies
Highlighted
Retired Employee
8 Views

The extent of the last

Jump to solution

The extent of the last dimension of a,b,c and d are, technically, 100, 9, 51, 5, but there's no way to determine that in the program. Passing a single element to an assumed-size array is called "sequence association", and the dummy argument (a,b,c,d) is associated with the remainder of the extent of the actual argument. (b is a bit strange - as there is actually one more element left over. Your example would have been easier to explain if the subscripts were 11 and 51.)

In pre-F77 days, it was popular to declare dummy arrays with a last bound of 1, relying on the lack of bounds checking in most early compilers. F77 added assumed-size arrays which replace the (1) hack.

Here's what the standard says (8.5.8.5):

The size of an assumed-size array is determined as follows.
 • If the effective argument associated with the assumed-size dummy array is an array of any type other than default character, the size is that of the effective argument.
 • If the actual argument corresponding to the assumed-size dummy array is an array element of any type other than default character with a subscript order value of r (9.5.3.2) in an array of size x, the size of the dummy array is x − r + 1.
 • If the actual argument is a default character array, default character array element, or a default character array element substring (9.4.1), and if it begins at character storage unit t of an array with c character storage units, the size of the dummy array is MAX (INT ((c − t + 1)/e), 0), where e is the length of an element in the dummy character array.
 • If the actual argument is a default character scalar that is not an array element or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), where e is the length of an element in the dummy character array and l is the length of the actual argument.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran

View solution in original post

0 Kudos
Highlighted
7 Views

Thanks you! That is really

Jump to solution

Thanks you! That is really helpful and very different from what I had inferred from how the assumed-size arrays get presented in the debugger

0 Kudos
Highlighted
Retired Employee
7 Views

The debugger shows them as (1

Jump to solution

The debugger shows them as (1) because it has no information about the actual bounds.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos