home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / educ / ada1for.doc next >
Encoding:
Text File  |  1988-05-03  |  5.1 KB  |  164 lines

  1.  
  2. The following terminal session illustrates a procedure
  3. for calling FORTRAN subprograms from an Ada mainline.
  4. The environment:
  5.  
  6.     DEC VAX 11/785 running VMS 4.1
  7.     DEC Ada compiler
  8.     DEC FORTRAN-77 compiler
  9.  
  10. Address questions to RCONN@SIMTEL20.
  11.  
  12.         -- Rick Conn
  13.  
  14. Session follows:
  15.  
  16. $ ! Demo of interfacing FORTRAN code to an Ada program
  17. $ ! by Rick Conn, TI Ada Technology Branch
  18. $ ! the FORTRAN code:
  19. $ type myprog.for
  20.                 subroutine myprint
  21.                 print *, 'This is a test'
  22.                 return
  23.                 end
  24.  
  25.  
  26.                 subroutine printit (value)
  27.                 print *, 'The value is ', value
  28.                 return
  29.                 end
  30.  
  31.                 subroutine iprintit (ivalue)
  32.                 print *, 'The integer value is ', ivalue
  33.                 return
  34.                 end
  35.  
  36.                 function fsin(x)
  37. c       I did this because I don't know where/name of FORTRAN Obj lib
  38. c       If I knew this, I could access it directly
  39.                 fsin = sin(x)
  40.                 return
  41.                 end
  42.  
  43.                 function fcos(x)
  44. c       I did this because I don't know where/name of FORTRAN Obj lib
  45. c       If I knew this, I could access it directly
  46.                 fcos = cos(x)
  47.                 return
  48.                 end
  49. $ ! the Ada mainline:
  50. $ type myptest.ada
  51. with text_io;
  52. procedure myptest is
  53.         procedure myprint;
  54.         procedure printit (value : float);
  55.         procedure iprintit (value : integer);
  56.  
  57.         function fsin(x : float) return float;
  58.         function fcos(x : float) return float;
  59.  
  60.         pragma interface(fortran, myprint);
  61.         pragma interface(fortran, printit);
  62.         pragma interface(fortran, iprintit);
  63.  
  64.         pragma interface(fortran, fsin);
  65.         pragma interface(fortran, fcos);
  66.  
  67.         package fio is new text_io.float_io(float);
  68.  
  69.         angle, x : float;
  70.         y1, y2 : float;
  71.         i : integer;
  72.  
  73. begin
  74.         x := 1.0;
  75.         i := 21;
  76.         myprint;  -- FORTRAN routine with no params
  77.         printit(x);  -- FORTRAN routine with REAL/FLOAT param
  78.         iprintit(i);  -- FORTRAN routine with INTEGER param
  79.         for j in 1..20 loop
  80.                 angle := float(j*18);
  81.                 x := angle * 3.1415926535 / 180.0;
  82.                 y1 := fsin(x);  -- FORTRAN sin function
  83.                 y2 := fcos(x);  -- FORTRAN cos function
  84.                 fio.put (angle,4,1);
  85.                 fio.put (y1,4,8);
  86.                 fio.put (y2,4,8);
  87.                 text_io.new_line;
  88.         end loop;
  89. end myptest;
  90. $ ! compile the .FOR file, creating an .OBJ file
  91. $ fortran myprog
  92. $ d
  93.  
  94. Directory USER4:[CONN.ADA]
  95.  
  96. LIB.DIR;1                 6  (RE,RWE,RE,RE)
  97. MYPROG.FOR;7              2  (RWE,RWED,RE,RE)
  98. MYPROG.OBJ;1              4  (RWE,RWED,RE,RE)
  99. MYPTEST.ADA;6             2  (RWE,RWED,RE,RE)
  100.  
  101. Total of 4 files, 14 blocks.
  102. $ ! place the .OBJ file into an object library of type .OLB
  103. $ lib mylib/create/object
  104. $ lib mylib myprog
  105. $ lib mylib/list
  106. Directory of OBJECT library USER4:[CONN.ADA]MYLIB.OLB;1 on 17-APR-1985 14:12:16
  107. Creation date:  17-APR-1985 14:12:03      Creator:  VAX-11 Librarian V04-00
  108. Revision date:  17-APR-1985 14:12:12      Library format:   3.0
  109. Number of modules:      5                 Max. key length:  31
  110. Other entries:          5                 Preallocated index blocks:     49
  111. Recoverable deleted blocks:      0        Total index blocks used:        2
  112. Max. Number history records:      20      Library history records:        1
  113.  
  114. FCOS
  115. FSIN
  116. IPRINTIT
  117. MYPRINT
  118. PRINTIT
  119. $ ! the library is ready
  120. $ ! compile the Ada mainline
  121. $ ada myptest
  122. $ ! link and include the library
  123. $ acs link myptest mylib/lib
  124. Invoking the VAX/VMS Linker
  125. $ ! done
  126. $ d
  127.  
  128. Directory USER4:[CONN.ADA]
  129.  
  130. LIB.DIR;1                 6  (RE,RWE,RE,RE)
  131. MYLIB.OLB;1              55  (RWE,RWED,RE,RE)
  132. MYPROG.FOR;7              2  (RWE,RWED,RE,RE)
  133. MYPROG.OBJ;1              4  (RWE,RWED,RE,RE)
  134. MYPTEST.ADA;6             2  (RWE,RWED,RE,RE)
  135. MYPTEST.EXE;1            10  (RWE,RWED,RE,RE)
  136.  
  137. Total of 6 files, 79 blocks.
  138. $ ! MYPTEST.EXE is ready to run
  139. $ run myptest
  140. This is a test
  141. The value is    1.000000    
  142. The integer value is           21
  143.    1.8E+01   3.09017003E-01   9.51056540E-01
  144.    3.6E+01   5.87785244E-01   8.09017003E-01
  145.    5.4E+01   8.09017003E-01   5.87785244E-01
  146.    7.2E+01   9.51056540E-01   3.09016973E-01
  147.    9.0E+01   1.00000000E+00  -4.37113883E-08
  148.    1.1E+02   9.51056480E-01  -3.09017032E-01
  149.    1.3E+02   8.09016883E-01  -5.87785423E-01
  150.    1.4E+02   5.87785184E-01  -8.09017062E-01
  151.    1.6E+02   3.09017032E-01  -9.51056480E-01
  152.    1.8E+02  -8.74227766E-08  -1.00000000E+00
  153.    2.0E+02  -3.09016973E-01  -9.51056540E-01
  154.    2.2E+02  -5.87785363E-01  -8.09016943E-01
  155.    2.3E+02  -8.09017122E-01  -5.87785065E-01
  156.    2.5E+02  -9.51056600E-01  -3.09016645E-01
  157.    2.7E+02  -1.00000000E+00   1.19248806E-08
  158.    2.9E+02  -9.51056480E-01   3.09017122E-01
  159.    3.1E+02  -8.09016824E-01   5.87785482E-01
  160.    3.2E+02  -5.87785304E-01   8.09016943E-01
  161.    3.4E+02  -3.09016943E-01   9.51056540E-01
  162.    3.6E+02   1.74845553E-07   1.00000000E+00
  163.