summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
Diffstat (limited to 'Examples')
-rw-r--r--Examples/fortran/array/Makefile29
-rw-r--r--Examples/fortran/array/example.c23
-rw-r--r--Examples/fortran/array/example.i8
-rw-r--r--Examples/fortran/array/runme.f34
-rw-r--r--Examples/fortran/simple/Makefile2
-rw-r--r--Examples/fortran/simple/example.c7
-rw-r--r--Examples/fortran/simple/example.i1
-rw-r--r--Examples/fortran/simple/runme.f7
-rw-r--r--Examples/fortran/string/Makefile29
-rw-r--r--Examples/fortran/string/example.c9
-rw-r--r--Examples/fortran/string/example.i6
-rw-r--r--Examples/fortran/string/runme.f23
12 files changed, 162 insertions, 16 deletions
diff --git a/Examples/fortran/array/Makefile b/Examples/fortran/array/Makefile
new file mode 100644
index 000000000..3643921d8
--- /dev/null
+++ b/Examples/fortran/array/Makefile
@@ -0,0 +1,29 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+RUNME = runme.f
+PROXY =
+MEMTOOL = valgrind --leak-check=full
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' fortran
+ $(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
+ TARGET='$(TARGET)' fortran_compile
+
+run:
+ env LD_LIBRARY_PATH=. ./runme
+
+memchk:
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CFLAGS='-g' fortran
+ $(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
+ TARGET='$(TARGET)' CFLAGS='-g' fortran_compile
+ env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
+
+clean:
+ rm -f *.o *.so *.out *.a *.exe *.dll *.dylib *_wrap* *_proxy* *~ runme
+
+check: all
diff --git a/Examples/fortran/array/example.c b/Examples/fortran/array/example.c
new file mode 100644
index 000000000..d720509f2
--- /dev/null
+++ b/Examples/fortran/array/example.c
@@ -0,0 +1,23 @@
+/* File : example.c */
+#include <stdio.h>
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int* incrArrayInt(int *x, int nmemb) {
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+void sayhi(char *str, int y, char *ret) {
+ if (ret != NULL) {
+ sprintf(ret, "hello %s", str);
+ }
+ return;
+}
diff --git a/Examples/fortran/array/example.i b/Examples/fortran/array/example.i
new file mode 100644
index 000000000..bf55fab52
--- /dev/null
+++ b/Examples/fortran/array/example.i
@@ -0,0 +1,8 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern void sayhi(char *x, int y, char *ret);
+//extern double Foo;
+%}
diff --git a/Examples/fortran/array/runme.f b/Examples/fortran/array/runme.f
new file mode 100644
index 000000000..5b89105b1
--- /dev/null
+++ b/Examples/fortran/array/runme.f
@@ -0,0 +1,34 @@
+! ----------------------------------------------------------------------
+! EXAMPLE: Calling a C function from fortran using swig.
+!
+! This simple example shows how to call a c funtion from Fortran
+!
+! ======================================================================
+! AUTHOR: Derrick Kearney, Purdue University
+! Copyright (c) 2005-2010 Purdue Research Foundation
+!
+! See the file "license.terms" for information on usage and
+! redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+! ======================================================================
+
+ program runme
+ IMPLICIT NONE
+
+ integer gcd, a, b , g
+
+ character*5 str
+ character*20 ret
+
+ a = 45
+ b = 105
+ g = 0
+
+ g = gcd(a, b)
+ write(*,*) "The gcd of ", a," and ", b, " is ", g
+
+ call sayhi(str, a, ret)
+ write(*,*) "The result of sayhi is ", ret
+
+
+! Swig_exit(0)
+ end program runme
diff --git a/Examples/fortran/simple/Makefile b/Examples/fortran/simple/Makefile
index 3643921d8..159300edb 100644
--- a/Examples/fortran/simple/Makefile
+++ b/Examples/fortran/simple/Makefile
@@ -1,5 +1,5 @@
TOP = ../..
-SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
+SWIG = $(TOP)/../preinst-swig -debug-typemap -debug-module 4 > tree.txt
SRCS = example.c
TARGET = example
INTERFACE = example.i
diff --git a/Examples/fortran/simple/example.c b/Examples/fortran/simple/example.c
index 871c3819c..d81afc269 100644
--- a/Examples/fortran/simple/example.c
+++ b/Examples/fortran/simple/example.c
@@ -15,10 +15,3 @@ int gcd(int x, int y) {
}
return g;
}
-
-void sayhi(char *str, int y, char *ret) {
- if (ret != NULL) {
- sprintf(ret, "hello %s", str);
- }
- return;
-}
diff --git a/Examples/fortran/simple/example.i b/Examples/fortran/simple/example.i
index bf55fab52..52b4dde83 100644
--- a/Examples/fortran/simple/example.i
+++ b/Examples/fortran/simple/example.i
@@ -3,6 +3,5 @@
%inline %{
extern int gcd(int x, int y);
-extern void sayhi(char *x, int y, char *ret);
//extern double Foo;
%}
diff --git a/Examples/fortran/simple/runme.f b/Examples/fortran/simple/runme.f
index 5b89105b1..fa25dcccb 100644
--- a/Examples/fortran/simple/runme.f
+++ b/Examples/fortran/simple/runme.f
@@ -16,9 +16,6 @@
integer gcd, a, b , g
- character*5 str
- character*20 ret
-
a = 45
b = 105
g = 0
@@ -26,9 +23,5 @@
g = gcd(a, b)
write(*,*) "The gcd of ", a," and ", b, " is ", g
- call sayhi(str, a, ret)
- write(*,*) "The result of sayhi is ", ret
-
-
! Swig_exit(0)
end program runme
diff --git a/Examples/fortran/string/Makefile b/Examples/fortran/string/Makefile
new file mode 100644
index 000000000..159300edb
--- /dev/null
+++ b/Examples/fortran/string/Makefile
@@ -0,0 +1,29 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig -debug-typemap -debug-module 4 > tree.txt
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+RUNME = runme.f
+PROXY =
+MEMTOOL = valgrind --leak-check=full
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' fortran
+ $(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
+ TARGET='$(TARGET)' fortran_compile
+
+run:
+ env LD_LIBRARY_PATH=. ./runme
+
+memchk:
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CFLAGS='-g' fortran
+ $(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
+ TARGET='$(TARGET)' CFLAGS='-g' fortran_compile
+ env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
+
+clean:
+ rm -f *.o *.so *.out *.a *.exe *.dll *.dylib *_wrap* *_proxy* *~ runme
+
+check: all
diff --git a/Examples/fortran/string/example.c b/Examples/fortran/string/example.c
new file mode 100644
index 000000000..85d00b612
--- /dev/null
+++ b/Examples/fortran/string/example.c
@@ -0,0 +1,9 @@
+/* File : example.c */
+#include <stdio.h>
+
+void sayhi(char *str, char *ret) {
+ if (ret != NULL) {
+ sprintf(ret, "hello %s", str);
+ }
+ return;
+}
diff --git a/Examples/fortran/string/example.i b/Examples/fortran/string/example.i
new file mode 100644
index 000000000..f9a57c7be
--- /dev/null
+++ b/Examples/fortran/string/example.i
@@ -0,0 +1,6 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern void sayhi(char *x, char *ret);
+%}
diff --git a/Examples/fortran/string/runme.f b/Examples/fortran/string/runme.f
new file mode 100644
index 000000000..db73d78fe
--- /dev/null
+++ b/Examples/fortran/string/runme.f
@@ -0,0 +1,23 @@
+! ----------------------------------------------------------------------
+! EXAMPLE: Calling a C function from fortran using swig.
+!
+! The string example shows how to call a c funtion from Fortran
+!
+! ======================================================================
+
+ program runme
+ IMPLICIT NONE
+
+ character (LEN=7) :: name="derrick"
+ character*20 ret
+
+ call sayhi(name, ret)
+ write(*,*) "The result of sayhi is: ", ret
+
+! This case does not work
+! call sayhi("derrick", ret)
+! write(*,*) "The result of sayhi is: ", ret
+
+
+! Swig_exit(0)
+ end program runme