Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing 2D array of unknown size to function in FORTRAN 95

Trying to input a 2D array with an unknown size, n, in one of its dimensions as the input to a function. So, the input will be (n, 3) and output (n, 1). These will represent n cartesian coordinates.

So far have been trying:



   function IterativeHarmonics(l, m, x)


      real :: IterativeHarmonics

      integer, intent(in) :: l, m

      real, intent(in) :: x(:,3)


      IterativeHarmonics = x(1,3)


   end function IterativeHarmonics


But this gives the errors Error: Bad specification for deferred shape array at (1) and Error: Function ‘x’ at (1) has no IMPLICIT type

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As with deferred-shape arrays, we cannot just partially assume the shape of an array.

That is,

real x(:,3)

is not allowed, even where we know the extent of the second dimension will always be 3. We must assume like

real x(:,:)

If you want to use assumed-shape arrays, but insist on the second extent being of a specific value, you’ll need to add your own checks. You can, of course, use an explicit shape where the first extent is passed:

real x(n,3)   ! n accessible somehow, probably as dummy

(The error about x being a function and of implicit type follows on from the faulty declaration.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading