Calling FORTRAN 77 from HP Pascal [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP Pascal/iX Programmer's Guide
Calling FORTRAN 77 from HP Pascal
The table and example in this section assume that the HP Pascal program
and the FORTRAN 77 routine that it calls are both compiled in Native
Mode. If the FORTRAN 77 routine is in a Compatibility Mode SL instead,
you must write a switch stub to access it from your HP Pascal program
(see "Switch Stubs" ).
Table 9-3 matches corresponding HP Pascal and FORTRAN 77 or FORTRAN
66/V types. (It contains only the types that are acceptable for formal
intrinsic parameters.) The variable n is an integer.
Table 9-3. Corresponding HP Pascal and FORTRAN 77 or FORTRAN 66/V Types
-------------------------------------------------------------------------------
| | |
| HP Pascal Type | Corresponding FORTRAN 77 or |
| | FORTRAN 66/V Type |
| | |
-------------------------------------------------------------------------------
| | |
| Array: Not PACKED | An array of a corresponding type. |
| | (Pascal arrays are stored in row-major |
| | order; FORTRAN arrays are stored in |
| | column-major order.) |
| | |
-------------------------------------------------------------------------------
| | |
| Array: PACKED | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| Boolean (false = 0, true = 1) | LOGICAL*1 (false = 0, true = 1) |
| | |
-------------------------------------------------------------------------------
| | |
| Char | CHARACTER |
| | |
-------------------------------------------------------------------------------
| | |
| Enumeration | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| File | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| Function | Function3 |
| | |
-------------------------------------------------------------------------------
| | |
| Function parameter or variable | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| Integer | INTEGER*4 |
| | |
-------------------------------------------------------------------------------
| | |
| Longreal | REAL*8 or DOUBLE PRECISION |
| | |
-------------------------------------------------------------------------------
| | |
| PAC of n characters | CHARACTER*x, x in 1..n 1,2 |
| | |
-------------------------------------------------------------------------------
| | |
| Pointer | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| Procedure | Subroutine3 |
| | |
-------------------------------------------------------------------------------
| | |
| Procedure parameter or variable | Not available |
| | |
-------------------------------------------------------------------------------
| | |
| Real | REAL or REAL*4 |
| | |
-------------------------------------------------------------------------------
| | |
| Record | Build equivalent record |
| | |
-------------------------------------------------------------------------------
| | |
| Set | Not available |
| | |
-------------------------------------------------------------------------------
Table 9-3. Corresponding HP Pascal and FORTRAN 77 or FORTRAN 66/V Types (cont.)
-------------------------------------------------------------------------------
| | |
| HP Pascal Type | Corresponding FORTRAN 77 or |
| | FORTRAN 66/V Type |
| | |
-------------------------------------------------------------------------------
| | |
| Shortint | INTEGER*2 |
| | |
-------------------------------------------------------------------------------
| | |
| String | CHARACTER*(*)2 |
| | |
-------------------------------------------------------------------------------
| | |
| String[n] | CHARACTER*(*)2 |
| | |
-------------------------------------------------------------------------------
| | |
| VAR parameter | Default parameter mechanism |
| | |
-------------------------------------------------------------------------------
| | |
| RECORD | COMPLEX |
| real_part : real ; | |
| imaginary_part : real ; | |
| END ; | |
| | |
-------------------------------------------------------------------------------
Table 9-3 Notes
1. When you call a Pascal routine from a FORTRAN routine, use the
FORTRAN directive $ALIAS in the FORTRAN compilation unit to
specify a nonstandard calling sequence for the Pascal routine.
Specify %REF for each character string parameter (the FORTRAN
default for character strings is %DESCR). See the example in "How
Non-Pascal Programs Call Pascal Routines" .
2. For calling FORTRAN 77 from Pascal only. In the FORTRAN 77
compilation unit, declare the parameter as CHARACTER*n or
CHARACTER*(*). For a PAC type HP Pascal parameter, HP Pascal
passes the address followed by the length. For either string type
HP Pascal parameter, HP Pascal passes the address of the data part
of the string followed by its current length. The current length
is loaded from the length field. For example:
A FORTRAN 77 routine:
CHARACTER*40 FUNCTION F77_Func (Str1,Str2)
CHARACTER*80 Str1
CHARACTER*(*) Str2
...
RETURN
END
An HP Pascal program that calls the FORTRAN 77 routine:
TYPE
Str40 = string[40] ;
Pac80 = PACKED ARRAY [1..80] OF char ;
FUNCTION F77_Func (VAR Str1 : Pac80 ;
VAR Str2 : Str40) : Str40 ;
EXTERNAL FTN77 ;
VAR
Vbl1, Vbl2 : Str40 ;
Pac1 : Pac80 ;
BEGIN { main program }
...
Vbl2 := strrtrim(F77_Func(Vbl1,Pac1)) ;
...
END ;
3. This is not correctly implemented in FORTRAN 77.
Example
The Pascal program Pascal_Fort calls the external FORTRAN 77 routine
FORTPRC.
Pascal program:
PROGRAM Pascal_Fort (input,output);
TYPE
char_str = PACKED ARRAY [1..20] OF char;
VAR
a_str : char_str;
int1,
int2,
sum : integer;
PROCEDURE fortprc (VAR cstr : char_str;
VAR inta : integer;
VAR intb : integer;
VAR total : integer); EXTERNAL FTN77;
BEGIN
a_str := 'Add these 2 numbers:';
int1 := 25;
int2 := 15;
writeln(a_str,int1,int2);
fortprc(a_str,int1,int2,sum);
writeln(a_str,sum);
END.
FORTRAN 77 routine:
SUBROUTINE FORTPRC(CSTR,INT1,INT2,SUM)
INTEGER INT1, INT2, SUM
CHARACTER CSTR*20
SUM = INT1 + INT2
CSTR = "SUM OF TWO NUMBERS: "
RETURN
END
MPE/iX 5.0 Documentation