Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Overbey2012-04-19 20:50:04 +0000
committerJeffrey Overbey2012-05-04 15:53:34 +0000
commita0751d848083be30bf1193a2842ba965f3e6f597 (patch)
tree9fb9629de6e4b7f7389a018ea20f978c3437db88
parentbe187d6c3332ba2f89d3c52234ac437c9c0a77ea (diff)
downloadorg.eclipse.photran-a0751d848083be30bf1193a2842ba965f3e6f597.tar.gz
org.eclipse.photran-a0751d848083be30bf1193a2842ba965f3e6f597.tar.xz
org.eclipse.photran-a0751d848083be30bf1193a2842ba965f3e6f597.zip
Updated mixed C+Fortran example to use Fortran 2003 C interop
-rw-r--r--org.eclipse.photran-samples/src-fortran-and-c/Makefile13
-rw-r--r--org.eclipse.photran-samples/src-fortran-and-c/c.c4
-rw-r--r--org.eclipse.photran-samples/src-fortran-and-c/fortran.f9044
3 files changed, 16 insertions, 45 deletions
diff --git a/org.eclipse.photran-samples/src-fortran-and-c/Makefile b/org.eclipse.photran-samples/src-fortran-and-c/Makefile
index 99ecf1a3..4ab9aff0 100644
--- a/org.eclipse.photran-samples/src-fortran-and-c/Makefile
+++ b/org.eclipse.photran-samples/src-fortran-and-c/Makefile
@@ -1,10 +1,7 @@
-# Requires g95 under Windows (since calling a C function; proprietary)
-
-clean:
- rm -f a.exe *.o
-
all:
gcc -g -c c.c
- g95 -g -c fortran.f90
- g95 -o a.exe c.o fortran.o
- rm *.o
+ gfortran -g -c fortran.f90
+ gfortran -o a.exe -g c.o fortran.o
+
+clean:
+ rm -f *.o a.exe \ No newline at end of file
diff --git a/org.eclipse.photran-samples/src-fortran-and-c/c.c b/org.eclipse.photran-samples/src-fortran-and-c/c.c
index b21f9c16..6c32fe1f 100644
--- a/org.eclipse.photran-samples/src-fortran-and-c/c.c
+++ b/org.eclipse.photran-samples/src-fortran-and-c/c.c
@@ -1,6 +1,6 @@
#include <stdio.h>
-void cfunction_()
+void cfunction(int n, float x)
{
- printf(" This is the C function\n");
+ printf(" This is the C function - %d %f\n", n, x);
}
diff --git a/org.eclipse.photran-samples/src-fortran-and-c/fortran.f90 b/org.eclipse.photran-samples/src-fortran-and-c/fortran.f90
index eef8e42a..b626be68 100644
--- a/org.eclipse.photran-samples/src-fortran-and-c/fortran.f90
+++ b/org.eclipse.photran-samples/src-fortran-and-c/fortran.f90
@@ -1,38 +1,12 @@
- external cfunction ! Defined in c.c
+ interface
+ subroutine cfunction(n, x) bind(c) ! Defined in c.c
+ use iso_c_binding
+ integer(kind=c_int), value :: n
+ real(kind=c_float), value :: x
+ end subroutine
+ end interface
print *, 'This is the Fortran program; I am going to call the C function now...'
- call cfunction()
- call sum(1.0,2.0,3.0)
- call factorial(3)
- print *, 'Now we are back in Fortran again'
-
-contains
-
- subroutine sum(x,y,z)
-
- x = x+y+z
-
- print *, x
-
- end subroutine sum
-
- subroutine factorial(j)
-
- p=1
- i=1
- do i=1,j
- p=p*i
- end do
-
- print *, j, "! = ", p
-
- end subroutine factorial
-
- subroutine sum2(x,y)
-
- p = x+y
-
- end subroutine sum2
-
-
+ call cfunction(1, 2.3)
end
+

Back to the top