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

  1. $ ! Demo of FORTRAN 77 calling Ada
  2. $ ! Environment: DEC VAX 11/785, DEC FORTRAN-77, DEC Ada
  3. $ ! the FORTRAN mainline:
  4. $ type formain.for
  5.  
  6.         call adapr1
  7.         i = 2
  8.         call adapr2(i)
  9.         x = 20.0
  10.         call adapr3(x)
  11.         j = iadapr4(0)
  12.         print *, 'The value of J is ', j
  13.         print *, 'The old value of X is ', x
  14.         call adapr5(x)
  15.         print *, 'The new value of X is ', x
  16.  
  17.         end
  18. $ ! the Ada subprograms:
  19. $ type adapr.ada
  20.  
  21. WITH text_io;
  22. PACKAGE io_support is
  23.     PACKAGE int_io IS NEW text_io.integer_io(integer);
  24.     PACKAGE fl_io IS NEW text_io.float_io(float);
  25. END io_support;
  26.  
  27.     WITH text_io;
  28.     PROCEDURE adapr1 IS
  29.     BEGIN
  30.         text_io.put ("This was printed by ADAPR1");
  31.         text_io.new_line;
  32.     END adapr1;
  33.     PRAGMA export_procedure (adapr1);
  34.  
  35.     WITH io_support, text_io; USE io_support;
  36.     PROCEDURE adapr2 (value : integer) IS
  37.     BEGIN
  38.         text_io.put ("Integer value from ADAPR2 IS ");
  39.         int_io.put (value,8);
  40.         text_io.new_line;
  41.     END adapr2;
  42.     PRAGMA export_procedure (adapr2);
  43.  
  44.     WITH io_support, text_io; USE io_support;
  45.     PROCEDURE adapr3 (value : float) IS
  46.     BEGIN
  47.         text_io.put ("Float value from ADAPR3 IS ");
  48.         fl_io.put (value,8,4);
  49.         text_io.new_line;
  50.     END adapr3;
  51.     PRAGMA export_procedure (adapr3, parameter_types => (float));
  52.  
  53.     FUNCTION iadapr4 (value : integer) RETURN integer IS
  54.     BEGIN
  55.         RETURN 10;
  56.     END iadapr4;
  57.     PRAGMA export_function (iadapr4, parameter_types => (integer),
  58.         result_type => integer);
  59.  
  60.     PROCEDURE adapr5 (value : IN OUT float) IS
  61.     BEGIN
  62.         value := value * 2.0;
  63.     END adapr5;
  64.     PRAGMA export_procedure (adapr5, parameter_types => (float));
  65.  
  66.  
  67.  
  68. $ ! compile the FORTRAN source and Ada source:
  69. $ fortran formain
  70. $ ada adapr
  71. $ ! link, and generate ADAPR1.EXE
  72. $ ! note that I specify the Ada routines by name in the LINK
  73. $ acs link/nomain adapr1,adapr2,adapr3,iadapr4,adapr5 formain.obj
  74. Invoking the VAX/VMS Linker
  75. $ ! now to run it
  76. $ run adapr1
  77. This was printed by ADAPR1
  78. Integer value from ADAPR2 IS        2
  79. Float value from ADAPR3 IS        2.0000E+01
  80. The value of J is           10
  81. The old value of X is    20.00000    
  82. The new value of X is    40.00000    
  83. $ ! notes: re VAX Ada Language Reference Manual, Field Test Draft, Oct 84
  84. $ !     section 13.9 (Interface to Other Languages)
  85. $ ! pragmas provided are:
  86. $ !    INTERFACE
  87. $ !    IMPORT_PROCEDURE, EXPORT_PROCEDURE
  88. $ !    IMPORT_FUNCTION, EXPORT_FUNCTION
  89. $ !    IMPORT_VALUED_PROCEDURE
  90. $ !    IMPORT_OBJECT, EXPORT_OBJECT
  91. $ !    IMPORT_EXCEPTION, EXPORT_EXCEPTION
  92. $ ! parameters may be passed by VALUE, REFERENCE, or DESCRIPTOR
  93.