commit 917b3765c4f20be657dab4d71fea8389e8be4a64 Author: baol Date: Mon May 13 14:04:30 2024 +0800 first commit diff --git a/.projectile b/.projectile new file mode 100644 index 0000000..e69de29 diff --git a/READMe.md b/READMe.md new file mode 100644 index 0000000..6545ac8 --- /dev/null +++ b/READMe.md @@ -0,0 +1,6 @@ +## call fortran routine from C++ function + +* a FORTRAN90 subroutine is like a C++ void function, and should be declared this way in the C++ code. The qualifier extern should also be used. +* a FORTRAN90 subroutine or function expects all its arguments to be passed by reference. This generally means simply that the C++ function must pass scalar variables by reference, not value. +* typically, when the FORTRAN90 compiler compiles the FORTRAN90 code, the names of functions and subroutines are stored with an appended underscore. In order for these names to be found by the C++ code, it is necessary that the C++ code declare and invoke the FORTRAN90 functions and subroutines with the underscore explicitly appended to the name. +* in many cases, a FORTRAN90 compiler is simply a "front end" to a corresponding C++ compiler, as in the case of the GNU compilers gfortran and g++, or the Intel compilers ifort and icpp. This means that, as long as the corresponding compilers are used to compile the FORTRAN90 and C++ codes, it is probably possible to use either compiler to link and load the object codes; however, the load command may need to specify explicitly certain libraries associated with one of the languages. For instance, if loading using the gcc command, it is necessary to include "-l gfortran" so that the FORTRAN90 I/O libraries, among others, are included in the build. diff --git a/bad b/bad new file mode 100755 index 0000000..8b8a4fd Binary files /dev/null and b/bad differ diff --git a/build/c_hello b/build/c_hello new file mode 100755 index 0000000..308c236 Binary files /dev/null and b/build/c_hello differ diff --git a/build/hello b/build/hello new file mode 100755 index 0000000..82dd0e3 Binary files /dev/null and b/build/hello differ diff --git a/example2.c b/example2.c new file mode 100644 index 0000000..1af1efb --- /dev/null +++ b/example2.c @@ -0,0 +1,6 @@ +#include + +int main (void) { + printf("Two plus two is %f\n", 4); + return 0; +} diff --git a/example3/Makefile b/example3/Makefile new file mode 100644 index 0000000..d401832 --- /dev/null +++ b/example3/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-Wall + +main: main.o hello_fn.o + +clean: + rm -f main main.o hello_fn.o diff --git a/example3/hello.h b/example3/hello.h new file mode 100644 index 0000000..6f27270 --- /dev/null +++ b/example3/hello.h @@ -0,0 +1 @@ +void hello(const char* name); diff --git a/example3/hello_fn.c b/example3/hello_fn.c new file mode 100644 index 0000000..a0983d4 --- /dev/null +++ b/example3/hello_fn.c @@ -0,0 +1,6 @@ +#include +#include "hello.h" + +void hello(const char* name) { + printf("Hello, %s!\n", name); +} diff --git a/example3/hello_fn.o b/example3/hello_fn.o new file mode 100644 index 0000000..6f6cc0a Binary files /dev/null and b/example3/hello_fn.o differ diff --git a/example3/main b/example3/main new file mode 100755 index 0000000..da2892b Binary files /dev/null and b/example3/main differ diff --git a/example3/main.c b/example3/main.c new file mode 100644 index 0000000..4220484 --- /dev/null +++ b/example3/main.c @@ -0,0 +1,6 @@ +#include "hello.h" + +int main(void) { + hello("world, everyone"); + return 0; +} diff --git a/example3/main.o b/example3/main.o new file mode 100644 index 0000000..e44a904 Binary files /dev/null and b/example3/main.o differ diff --git a/example4/main b/example4/main new file mode 100755 index 0000000..3528bb2 Binary files /dev/null and b/example4/main differ diff --git a/example4/main.c b/example4/main.c new file mode 100644 index 0000000..6f6c765 --- /dev/null +++ b/example4/main.c @@ -0,0 +1,9 @@ +#include +#include + +int main(void) { + double x = 2.0; + double y = sqrt(x); + printf("the square root of %f is %f \n", x, y); + return 0; +} diff --git a/example5/a.out b/example5/a.out new file mode 100755 index 0000000..2b43e1e Binary files /dev/null and b/example5/a.out differ diff --git a/example5/dtest.c b/example5/dtest.c new file mode 100644 index 0000000..05547b6 --- /dev/null +++ b/example5/dtest.c @@ -0,0 +1,10 @@ +#include + +int main(void) { +#ifdef TEST + printf("TEST mode\n"); +#endif + printf("Running...\n"); + printf("value of NUM is %d\n", NUM); + return 0; +} diff --git a/example6/.#hello.cc b/example6/.#hello.cc new file mode 120000 index 0000000..d372cae --- /dev/null +++ b/example6/.#hello.cc @@ -0,0 +1 @@ +shudws@shudws.5723:1715510568 \ No newline at end of file diff --git a/example6/a.out b/example6/a.out new file mode 100755 index 0000000..7c017ea Binary files /dev/null and b/example6/a.out differ diff --git a/example6/hello b/example6/hello new file mode 100755 index 0000000..7c017ea Binary files /dev/null and b/example6/hello differ diff --git a/example6/hello.cc b/example6/hello.cc new file mode 100644 index 0000000..1fff3d8 --- /dev/null +++ b/example6/hello.cc @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello, world\n"; + return 0; +} diff --git a/example6/hello.o b/example6/hello.o new file mode 100644 index 0000000..f7ae8a6 Binary files /dev/null and b/example6/hello.o differ diff --git a/hello.F90 b/hello.F90 new file mode 100644 index 0000000..5827201 --- /dev/null +++ b/hello.F90 @@ -0,0 +1,5 @@ +program hello + ! this is comment line + + print *, "hello world!" +end program hello diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..f8317f2 --- /dev/null +++ b/hello.c @@ -0,0 +1,6 @@ +#include + +int main (void) { + printf("Hello, world!\n"); + return 0; +}