program prob2_main ! !******************************************************************************* ! !! PROB2_MAIN is a FORTRAN program that calls a C routine. ! ! ! Routines in C are all called "functions", but if a C function is ! "void", then it seems much like a FORTRAN subroutine. Otherwise, ! a C function is similar to a FORTRAN function. ! implicit none ! double precision d1 double precision d2 double precision d3 double precision d4 double precision double_add_func integer i1 integer i2 integer i3 integer i4 integer int_add_func real r1 real r2 real r3 real r4 real read_add_func ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'PROB2_MAIN' write ( *, '(a)' ) ' Demonstrate how a FORTRAN program ' write ( *, '(a)' ) ' can call a C routine.' i1 = 42 i2 = 22 call int_add_sub ( i1, i2, i3 ) i4 = int_add_func ( i1, i2 ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Set the value of two integers I1 and I2.' write ( *, '(a)' ) ' Call a C routine to compute I1 + I2.' write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' I1 = ', i1 write ( *, '(a,i6)' ) ' I2 = ', i2 write ( *, '(a,i6)' ) ' C "subroutine" INT_ADD_SUB returns output I3 = ', i3 write ( *, '(a,i6)' ) ' C function INT_ADD_FUNC returns output I4 = ', i4 r1 = 42.0E+00 r2 = 22.0E+00 call real_add_sub ( r1, r2, r3 ) r4 = real_add_func ( r1, r2 ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Set the value of two reals R1 and R2.' write ( *, '(a)' ) ' Call a C routine to compute R1 + R2.' write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' R1 = ', r1 write ( *, '(a,g14.6)' ) ' R2 = ', r2 write ( *, '(a,g14.6)' ) ' C "subroutine" REAL_ADD_SUB returns output R3 = ', r3 write ( *, '(a,g14.6)' ) ' C function REAL_ADD_FUNC returns output R4 = ', r4 d1 = 42.0D+00 d2 = 22.0D+00 call double_add_sub ( d1, d2, d3 ) d4 = double_add_func ( d1, d2 ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Set the value of two double precision values D1 and D2.' write ( *, '(a)' ) ' call a C routine to compute D1 + D2.' write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' D1 = ', d1 write ( *, '(a,g14.6)' ) ' D2 = ', d2 write ( *, '(a,g14.6)' ) ' C "subroutine" DOUBLE_ADD_SUB returns output D3 = ', d3 write ( *, '(a,g14.6)' ) ' C function DOUBLE_ADD_FUNC returns output D4 = ', d4 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'PROB2_MAIN:' write ( *, '(a)' ) ' Normal end of execution.' stop end