Skip to content

Commit

Permalink
Merge branch 'IEaddition' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjridley authored Nov 17, 2023
2 parents 33d7f73 + 6f8182b commit 5844596
Show file tree
Hide file tree
Showing 82 changed files with 25,931 additions and 68 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ set (CMAKE_CXX_STANDARD 11)
project(Aether LANGUAGES CXX
VERSION 2023.0)


# cmake -DUSE_FORTRAN=ON ..
if (USE_FORTRAN)
enable_language(Fortran)
file(GLOB MSIS_FILES ${PROJECT_SOURCE_DIR}/ext/MSIS/*.[fF]90)
file(GLOB IE_FILES ${PROJECT_SOURCE_DIR}/ext/IE/*.[fF]*)
add_definitions(-DFORTRAN)
else()
set(MSIS_FILES )
set(IE_FILES )
endif()

set(CMAKE_CXX_STANDARD 11)

# Directory variables
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
set(MAIN_DIR ${PROJECT_SOURCE_DIR}/src/main)
Expand All @@ -23,16 +25,16 @@ set(RUN_DIR ${PROJECT_SOURCE_DIR}/run)


if(TEST_INTERPOLATION)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${MAIN_DIR}/main_test_interpolation.cpp)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${IE_FILES} ${MAIN_DIR}/main_test_interpolation.cpp)
elseif(TEST_COORD)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${MAIN_DIR}/main_test_coord.cpp)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${IE_FILES} ${MAIN_DIR}/main_test_coord.cpp)
elseif(TEST_EXCHANGE)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${MAIN_DIR}/main_test_exchange.cpp)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${IE_FILES} ${MAIN_DIR}/main_test_exchange.cpp)
set(USE_DOUBLE_PRECISION True)
elseif(TEST_GRADIENT)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${MAIN_DIR}/main_test_gradient.cpp)
else()
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${MAIN_DIR}/main.cpp)
add_executable(aether ${SRC_FILES} ${MSIS_FILES} ${IE_FILES} ${MAIN_DIR}/main.cpp)
endif()

if(USE_DOUBLE_PRECISION)
Expand All @@ -45,7 +47,6 @@ endif()
# Set compiler and cmake options
target_compile_options(aether PUBLIC -ffast-math -O3)
set(SHARE_INCLUDE ${PROJECT_SOURCE_DIR}/share/include)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_FIND_ROOT_PATH ${SHARE_INCLUDE}
${CMAKE_FIND_ROOT_PATH}
Expand Down
19 changes: 19 additions & 0 deletions edu/examples/Fortran/main_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
// g++ main_v2.o print_hi.o -o main -lgfortran

#include <iostream>
#include <cstring>

extern "C" void print_hi(void);
extern "C" void print_double(int *i, float *x, float *y);
extern "C" void pass_arrays(int[], int[]);
extern "C" void get_array(int[]);
extern "C" void test_passing_string(int[]);

using namespace std;

const int iLength_ = 100;

int* copy_string_to_int(string inString) {
const int length = inString.length();
// declaring character array (+1 for null terminator)
int* outArray = new int[iLength_];
for (int i = 0; i < length; i++) {
outArray[i] = inString[i];
}
return outArray;
}

int main() {
int j;
float x, y;
Expand All @@ -37,5 +51,10 @@ int main() {
for (int i = 0; i < 10; i++)
std::cout << "c++ (saved fortran) " << i << ": " << array_back[i] << "\n";

string testString = "this is a test: UA/input/file.csv";
int* testArray = copy_string_to_int(testString);

test_passing_string(testArray);

return 0;
}
46 changes: 42 additions & 4 deletions edu/examples/Fortran/print_hi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,51 @@ module memories

end module memories

subroutine convert_int_to_string(inArray, outString, length)
implicit none
integer, intent(in) :: length
integer, dimension(length), intent(in) :: inArray
character(length), intent(out) :: outString

integer :: i
do i = 1, length
if (inArray(i) > 1) then
write(*,*) 'for : ', i, inArray(i)
outString(i:i) = achar(inArray(i))
else
outString(i:i) = achar(0)
endif
enddo

end subroutine convert_int_to_string

subroutine test_passing_string(intArray) bind(C, name = 'test_passing_string')
implicit none
integer, parameter :: iLength_ = 100
integer :: intArray(iLength_)
character(iLength_) :: charArray
integer :: i

call convert_int_to_string(intArray, charArray, iLength_)

! do i = 1, iLength_
! if (intArray(i) > 1) then
! write(*,*) 'for : ', i, intArray(i)
! charArray(i:i) = achar(intArray(i))
! else
! charArray(i:i) = ' '
! endif
! enddo

write(*,*) "string : ", charArray
end subroutine test_passing_string

subroutine print_hi() bind(C)
subroutine print_hi() bind(C, name = 'print_hi')
implicit none
write(*,*) "Hello from Fortran."
end subroutine print_hi

subroutine print_double(i, x, y) bind(C)
subroutine print_double(i, x, y) bind(C, name = 'print_double')
implicit none
integer :: i
real :: x
Expand All @@ -23,7 +61,7 @@ subroutine print_double(i, x, y) bind(C)
write(*,*) "Real in Fortran: ", x
end subroutine print_double

subroutine pass_arrays(array, twotimes) bind(C)
subroutine pass_arrays(array, twotimes) bind(C, name = 'pass_arrays')

use memories

Expand All @@ -38,7 +76,7 @@ subroutine pass_arrays(array, twotimes) bind(C)
enddo
end subroutine pass_arrays

subroutine get_array(array_back) bind(C)
subroutine get_array(array_back) bind(C, name = 'get_array')

use memories

Expand Down
Loading

0 comments on commit 5844596

Please sign in to comment.