forked from johannesgerer/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex1_main.f90
129 lines (119 loc) · 3.64 KB
/
ex1_main.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
program main
!*****************************************************************************80
!
!! MAIN is the main program for EX1.
!
! Discussion:
!
! EX1 is a mixed FORTRAN90/C program.
!
! Discussion:
!
! 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.
!
! The details of this routine depend on the machine being used
! and the compilers involved. In some cases, you need to tell the
! FORTRAN compiler not to append an underscore to symbolic names.
!
! For instance, on the DEC/COMPAQ ALPHA, you do this with the command
!
! fort -assume nounderscore myprog.f90
!
! and with the GFORTRAN compiler you say
!
! gfortran -fno-underscoring myprog.f90
!
! On other machines, the FORTRAN compiler may append an underscore,
! and you may have to append a corresponding underscore to the names
! of the routines in the C text (but not in the FORTRAN code!).
!
! Also, if you use a FORTRAN command to link and load the object
! files, you may need to include an explicit request for the C libraries,
! so that the C routines can access routines that they need.
! This might be done by a command like:
!
! fort myprog.o mysub.o -lm -lc
!
! or
!
! f77 myprog.o mysub.o -lm -lc
!
! but of course, the actual names and locations of the necessary C
! libraries can vary from machine to machine.
!
! Modified:
!
! 18 July 2003
!
! Author:
!
! John Burkardt
!
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 real_add_func
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'EX1'
write ( *, '(a)' ) ' FORTRAN90 main program'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Demonstrate how a FORTRAN90 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,i8)' ) ' Input I1 = ', i1
write ( *, '(a,i8)' ) ' Input I2 = ', i2
write ( *, '(a,i8)' ) ' INT_ADD_SUB returns I3 = ', i3
write ( *, '(a,i8)' ) ' INT_ADD_FUNC returns 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)' ) ' Input R1 = ', r1
write ( *, '(a,g14.6)' ) ' Input R2 = ', r2
write ( *, '(a,g14.6)' ) ' REAL_ADD_SUB returns R3 = ', r3
write ( *, '(a,g14.6)' ) ' REAL_ADD_FUNC returns 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)' ) ' Input D1 = ', d1
write ( *, '(a,g14.6)' ) ' Input D2 = ', d2
write ( *, '(a,g14.6)' ) ' DOUBLE_ADD_SUB returns output D3 = ', d3
write ( *, '(a,g14.6)' ) ' DOUBLE_ADD_FUNC returns output D4 = ', d4
!
! Terminate.
!
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'PROB2_MAIN:'
write ( *, '(a)' ) ' Normal end of execution.'
stop
end