Returning Values in Fortran 77 
Author Message
 Returning Values in Fortran 77

Hello,

I'm about to write Dijkstra's shortest Path algorithm in fortran (for me it
is the first program in fortran). Now I need to write a function which
returns an array, but  I don't know how...
I tried the following :

DIMENSION INTEGER FUNCTION f (x,y)

but this doesn't work...

Thanks for helping me...

Martin



Sun, 17 Jul 2005 05:30:16 GMT  
 Returning Values in Fortran 77

Quote:

> Now I need to write a function which
> returns an array, but  I don't know how...

You can't do that in f77.  Period.  It is an f90 feature.  F90 adds
a *LOT* of array functionality that f77 doesn't have.

For f77, if you need to return an array, you'll have to do it as a
subroutine.

--
Richard Maine                       |  Good judgment comes from experience;
email: my last name at host.domain  |  experience comes from bad judgment.
host: altair, domain: dfrc.nasa.gov |        -- Mark Twain



Sun, 17 Jul 2005 06:05:41 GMT  
 Returning Values in Fortran 77

Quote:

>I'm about to write Dijkstra's shortest Path algorithm in Fortran (for me it
>is the first program in fortran). Now I need to write a function which
>returns an array, but  I don't know how...

You can't in F77.  You can in F90 (but need an explicit interface for
the function visible to the caller - a point many newcomers to the
language miss.)

If you are sticking with F77, you'll have to make the array an
argument to a subroutine.


Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Fortran and Compaq Visual Fortran:
  http://intel.com/IDS/community



Sun, 17 Jul 2005 06:00:14 GMT  
 Returning Values in Fortran 77
Can't do it in F77.  Here is how it might look
in F (or Fortran 95):

program p
print *, f(2)
contains

function f(n) result(rf)

integer, intent(in) :: n
real, dimension(9) :: rf
integer :: i

rf = (/ (n*i, i = 1, 9) /)

end function f

end program p

You can write a subroutine with an extra argument
that returns the array.

Quote:

> Hello,

> I'm about to write Dijkstra's shortest Path algorithm in Fortran (for me it
> is the first program in fortran). Now I need to write a function which
> returns an array, but  I don't know how...
> I tried the following :

> DIMENSION INTEGER FUNCTION f (x,y)

> but this doesn't work...

> Thanks for helping me...

> Martin

--
Walt Brainerd         +1-877-355-6640 (voice & fax)
The Fortran Company   +1-520-760-1397 (outside USA)

Tucson, AZ 85750 USA  http://www.fortran.com


Sun, 17 Jul 2005 06:14:33 GMT  
 Returning Values in Fortran 77



Quote:
> Hello,

> I'm about to write Dijkstra's shortest Path algorithm in Fortran

If you succeed in writing it in F77, pls make it avail to see what we
can do reducing its statements using F9x's syntax..

Hey, I might even post a shortest path benchmark, wont that be swell
!!



Sun, 17 Jul 2005 16:37:53 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Intel fortran and fortran 77 standard!

2. Fortran 77 code using Fortran 90 compiler

3. Fortran 77 vs Fortran 90/95

4. Fortran 90 -> Fortran 77 translator

5. Creating - Fortran 77 dll for use in Visual Basic 6.0 (not using Compaq Visual Fortran)

6. HELP: How to translate Fortran 77 to Fortran 90

7. HELP: How to translate Fortran 77 to Fortran 90

8. problems converting Fortran 77 code to Fortran 90

9. Fortran 77 -> Fortran 95

10. Fortran Compiler F77L - EM32 FORTRAN 77, version 5.20

11. Watcom Fortran 77 and Fortran 90

12. Differences between MS-Fortran and fortran 77?

 

 
Powered by phpBB® Forum Software