first commit
This commit is contained in:
commit
917b3765c4
0
.projectile
Normal file
0
.projectile
Normal file
6
READMe.md
Normal file
6
READMe.md
Normal file
@ -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.
|
BIN
build/c_hello
Executable file
BIN
build/c_hello
Executable file
Binary file not shown.
BIN
build/hello
Executable file
BIN
build/hello
Executable file
Binary file not shown.
6
example2.c
Normal file
6
example2.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main (void) {
|
||||
printf("Two plus two is %f\n", 4);
|
||||
return 0;
|
||||
}
|
7
example3/Makefile
Normal file
7
example3/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall
|
||||
|
||||
main: main.o hello_fn.o
|
||||
|
||||
clean:
|
||||
rm -f main main.o hello_fn.o
|
1
example3/hello.h
Normal file
1
example3/hello.h
Normal file
@ -0,0 +1 @@
|
||||
void hello(const char* name);
|
6
example3/hello_fn.c
Normal file
6
example3/hello_fn.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include "hello.h"
|
||||
|
||||
void hello(const char* name) {
|
||||
printf("Hello, %s!\n", name);
|
||||
}
|
BIN
example3/hello_fn.o
Normal file
BIN
example3/hello_fn.o
Normal file
Binary file not shown.
BIN
example3/main
Executable file
BIN
example3/main
Executable file
Binary file not shown.
6
example3/main.c
Normal file
6
example3/main.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "hello.h"
|
||||
|
||||
int main(void) {
|
||||
hello("world, everyone");
|
||||
return 0;
|
||||
}
|
BIN
example3/main.o
Normal file
BIN
example3/main.o
Normal file
Binary file not shown.
BIN
example4/main
Executable file
BIN
example4/main
Executable file
Binary file not shown.
9
example4/main.c
Normal file
9
example4/main.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
double x = 2.0;
|
||||
double y = sqrt(x);
|
||||
printf("the square root of %f is %f \n", x, y);
|
||||
return 0;
|
||||
}
|
BIN
example5/a.out
Executable file
BIN
example5/a.out
Executable file
Binary file not shown.
10
example5/dtest.c
Normal file
10
example5/dtest.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
#ifdef TEST
|
||||
printf("TEST mode\n");
|
||||
#endif
|
||||
printf("Running...\n");
|
||||
printf("value of NUM is %d\n", NUM);
|
||||
return 0;
|
||||
}
|
1
example6/.#hello.cc
Symbolic link
1
example6/.#hello.cc
Symbolic link
@ -0,0 +1 @@
|
||||
shudws@shudws.5723:1715510568
|
BIN
example6/a.out
Executable file
BIN
example6/a.out
Executable file
Binary file not shown.
BIN
example6/hello
Executable file
BIN
example6/hello
Executable file
Binary file not shown.
6
example6/hello.cc
Normal file
6
example6/hello.cc
Normal file
@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, world\n";
|
||||
return 0;
|
||||
}
|
BIN
example6/hello.o
Normal file
BIN
example6/hello.o
Normal file
Binary file not shown.
5
hello.F90
Normal file
5
hello.F90
Normal file
@ -0,0 +1,5 @@
|
||||
program hello
|
||||
! this is comment line
|
||||
|
||||
print *, "hello world!"
|
||||
end program hello
|
Loading…
x
Reference in New Issue
Block a user