1
votes

Consider the following short program (Fortran95):

   write(*,*) shape(2)
   end

I tried running this with Fortran compilers (gfortran 4.8.2) and Absoft Pro Fortran 13.0.0 (mac) and I get the following result:

local $./a.out 

local $

update: Also tried gfortran 4.4.7 (linux with the same result.

Here is what documentation of shape in gfortran says:

RESULT = SHAPE(SOURCE [, KIND]) 

Arguments:
SOURCE Shall be an array or scalar of any type. If SOURCE is a pointer it must be associated and allocatable arrays must be allocated.

Return value:
An INTEGER array of rank one with as many elements as SOURCE has dimensions. The elements of the resulting array correspond to the extend of SOURCE along the respective dimensions. If SOURCE is a scalar, the result is the rank one array of size zero. If KIND is absent, the return value has the default integer kind otherwise the specified kind.

In other words, I see only a newline and not a result. Should it not tell me that the shape is 1?

1

1 Answers

5
votes

It is correctly printing all the elements of the size-zero array shape returns. Printing an array of length zero results in zero numbers being printed.

It's the rank (number of dimensions) that is 1, not the length. That is, the result isn't a scalar or a matrix or some higher-order array. It's a vector. It just happens to be a vector with no elements.