fortran example
This commit is contained in:
10
rust-to-fortran/Cargo.toml
Normal file
10
rust-to-fortran/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust-to-fortran"
|
||||||
|
version = "0.1.0"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libc = "0.2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cc = "1.0"
|
||||||
7
rust-to-fortran/build.rs
Normal file
7
rust-to-fortran/build.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
extern crate cc;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
cc::Build::new()
|
||||||
|
.file("src/double.f90")
|
||||||
|
.compile("libdouble.a");
|
||||||
|
}
|
||||||
16
rust-to-fortran/src/double.f90
Normal file
16
rust-to-fortran/src/double.f90
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module wrapper
|
||||||
|
|
||||||
|
implicit none
|
||||||
|
private
|
||||||
|
public double_input
|
||||||
|
|
||||||
|
contains
|
||||||
|
|
||||||
|
function double_input(input)
|
||||||
|
implicit none
|
||||||
|
integer :: input, double_input
|
||||||
|
|
||||||
|
double_input = 2*input
|
||||||
|
end function
|
||||||
|
|
||||||
|
end module wrapper
|
||||||
13
rust-to-fortran/src/main.rs
Normal file
13
rust-to-fortran/src/main.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
extern crate libc;
|
||||||
|
|
||||||
|
// Consider using the `nm` utility on compiled Fortran files to get the function names
|
||||||
|
|
||||||
|
extern {
|
||||||
|
fn __wrapper_MOD_double_input(input: &libc::c_int) -> libc::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = 4;
|
||||||
|
let output = unsafe { __wrapper_MOD_double_input(&input) };
|
||||||
|
println!("{} * 2 = {}", input, output);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user