8

The FORTRAN subroutine,

FixVec.f

Fixed Arrays

For a fixed-array parameter, pass the same type and size by reference:

subroutine FixVec ( V, Sum ) integer Sum

integer V(0:8) integer i

Sum = 0

do 2 i = 0, 8

2Sum = Sum + V(i) return

end

The Pascal main program,

FixVecmain.p

The commands to compile and execute FixVec.f and

FixVecmain.p

program FixVecmain(output);

type

VecTyp = array [0..8] of integer;

var

V:VecTyp := [1, 2, 3, 4, 5, 6, 7, 8, 9]; Sum: integer;

procedure fixvec(var XV: VecTyp; var XSum: integer); external fortran;

begin

fixvec(V, Sum); writeln(Sum: 4) end. { FixVecmain }

hostname% f77 -c FixVec.f FixVec.f:

fixvec:

hostname% pc FixVec.o FixVecmain.p -lpfc -lF77 hostname% a.out

45

The FORTRAN–Pascal Interface

191

Page 215
Image 215
HP SunSoft Pascal 4.0 manual Commands to compile and execute FixVec.f, FORTRAN-Pascal Interface 191