home *** CD-ROM | disk | FTP | other *** search
-
- The following terminal session illustrates a procedure
- for calling FORTRAN subprograms from an Ada mainline.
- The environment:
-
- DEC VAX 11/785 running VMS 4.1
- DEC Ada compiler
- DEC FORTRAN-77 compiler
-
- Address questions to RCONN@SIMTEL20.
-
- -- Rick Conn
-
- Session follows:
-
- $ ! Demo of interfacing FORTRAN code to an Ada program
- $ ! by Rick Conn, TI Ada Technology Branch
- $ ! the FORTRAN code:
- $ type myprog.for
- subroutine myprint
- print *, 'This is a test'
- return
- end
-
-
- subroutine printit (value)
- print *, 'The value is ', value
- return
- end
-
- subroutine iprintit (ivalue)
- print *, 'The integer value is ', ivalue
- return
- end
-
- function fsin(x)
- c I did this because I don't know where/name of FORTRAN Obj lib
- c If I knew this, I could access it directly
- fsin = sin(x)
- return
- end
-
- function fcos(x)
- c I did this because I don't know where/name of FORTRAN Obj lib
- c If I knew this, I could access it directly
- fcos = cos(x)
- return
- end
- $ ! the Ada mainline:
- $ type myptest.ada
- with text_io;
- procedure myptest is
- procedure myprint;
- procedure printit (value : float);
- procedure iprintit (value : integer);
-
- function fsin(x : float) return float;
- function fcos(x : float) return float;
-
- pragma interface(fortran, myprint);
- pragma interface(fortran, printit);
- pragma interface(fortran, iprintit);
-
- pragma interface(fortran, fsin);
- pragma interface(fortran, fcos);
-
- package fio is new text_io.float_io(float);
-
- angle, x : float;
- y1, y2 : float;
- i : integer;
-
- begin
- x := 1.0;
- i := 21;
- myprint; -- FORTRAN routine with no params
- printit(x); -- FORTRAN routine with REAL/FLOAT param
- iprintit(i); -- FORTRAN routine with INTEGER param
- for j in 1..20 loop
- angle := float(j*18);
- x := angle * 3.1415926535 / 180.0;
- y1 := fsin(x); -- FORTRAN sin function
- y2 := fcos(x); -- FORTRAN cos function
- fio.put (angle,4,1);
- fio.put (y1,4,8);
- fio.put (y2,4,8);
- text_io.new_line;
- end loop;
- end myptest;
- $ ! compile the .FOR file, creating an .OBJ file
- $ fortran myprog
- $ d
-
- Directory USER4:[CONN.ADA]
-
- LIB.DIR;1 6 (RE,RWE,RE,RE)
- MYPROG.FOR;7 2 (RWE,RWED,RE,RE)
- MYPROG.OBJ;1 4 (RWE,RWED,RE,RE)
- MYPTEST.ADA;6 2 (RWE,RWED,RE,RE)
-
- Total of 4 files, 14 blocks.
- $ ! place the .OBJ file into an object library of type .OLB
- $ lib mylib/create/object
- $ lib mylib myprog
- $ lib mylib/list
- Directory of OBJECT library USER4:[CONN.ADA]MYLIB.OLB;1 on 17-APR-1985 14:12:16
- Creation date: 17-APR-1985 14:12:03 Creator: VAX-11 Librarian V04-00
- Revision date: 17-APR-1985 14:12:12 Library format: 3.0
- Number of modules: 5 Max. key length: 31
- Other entries: 5 Preallocated index blocks: 49
- Recoverable deleted blocks: 0 Total index blocks used: 2
- Max. Number history records: 20 Library history records: 1
-
- FCOS
- FSIN
- IPRINTIT
- MYPRINT
- PRINTIT
- $ ! the library is ready
- $ ! compile the Ada mainline
- $ ada myptest
- $ ! link and include the library
- $ acs link myptest mylib/lib
- Invoking the VAX/VMS Linker
- $ ! done
- $ d
-
- Directory USER4:[CONN.ADA]
-
- LIB.DIR;1 6 (RE,RWE,RE,RE)
- MYLIB.OLB;1 55 (RWE,RWED,RE,RE)
- MYPROG.FOR;7 2 (RWE,RWED,RE,RE)
- MYPROG.OBJ;1 4 (RWE,RWED,RE,RE)
- MYPTEST.ADA;6 2 (RWE,RWED,RE,RE)
- MYPTEST.EXE;1 10 (RWE,RWED,RE,RE)
-
- Total of 6 files, 79 blocks.
- $ ! MYPTEST.EXE is ready to run
- $ run myptest
- This is a test
- The value is 1.000000
- The integer value is 21
- 1.8E+01 3.09017003E-01 9.51056540E-01
- 3.6E+01 5.87785244E-01 8.09017003E-01
- 5.4E+01 8.09017003E-01 5.87785244E-01
- 7.2E+01 9.51056540E-01 3.09016973E-01
- 9.0E+01 1.00000000E+00 -4.37113883E-08
- 1.1E+02 9.51056480E-01 -3.09017032E-01
- 1.3E+02 8.09016883E-01 -5.87785423E-01
- 1.4E+02 5.87785184E-01 -8.09017062E-01
- 1.6E+02 3.09017032E-01 -9.51056480E-01
- 1.8E+02 -8.74227766E-08 -1.00000000E+00
- 2.0E+02 -3.09016973E-01 -9.51056540E-01
- 2.2E+02 -5.87785363E-01 -8.09016943E-01
- 2.3E+02 -8.09017122E-01 -5.87785065E-01
- 2.5E+02 -9.51056600E-01 -3.09016645E-01
- 2.7E+02 -1.00000000E+00 1.19248806E-08
- 2.9E+02 -9.51056480E-01 3.09017122E-01
- 3.1E+02 -8.09016824E-01 5.87785482E-01
- 3.2E+02 -5.87785304E-01 8.09016943E-01
- 3.4E+02 -3.09016943E-01 9.51056540E-01
- 3.6E+02 1.74845553E-07 1.00000000E+00
- $
-