generated from ENCCS/sphinx-lesson-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fortran code sample for 2nd exercise (conditioals)
- Loading branch information
1 parent
0d182f1
commit 9593a59
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
program hello_world | ||
|
||
use messaging | ||
|
||
implicit none | ||
|
||
type(Messenger) :: hello, bye | ||
|
||
hello%message_ = 'Hello, CMake world!' | ||
print *, print_message(hello) | ||
|
||
bye%message_ = 'Bye, CMake world!' | ||
print *, print_message(bye) | ||
|
||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module messaging | ||
|
||
implicit none | ||
|
||
public Messenger | ||
type Messenger | ||
character(len=19) :: message_ | ||
end type | ||
|
||
public print_message | ||
|
||
private | ||
|
||
contains | ||
|
||
pure function print_message(postman) result(m) | ||
|
||
type(Messenger), intent(in) :: postman | ||
character(len=19) :: m | ||
|
||
m = postman%message_ | ||
|
||
end function | ||
|
||
end module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# set minimum cmake version | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
# project name and language | ||
project(conditionals LANGUAGES Fortran) | ||
|
||
set(MAKE_SHARED_LIBRARY OFF) | ||
|
||
if(MAKE_SHARED_LIBRARY) | ||
message(STATUS "Build shared library") | ||
add_library(message SHARED message.f90) | ||
else() | ||
message(STATUS "Build static library") | ||
add_library(message STATIC message.f90) | ||
endif() | ||
|
||
add_executable(hello-world hello-world.f90) | ||
|
||
target_link_libraries(hello-world PRIVATE message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
program hello_world | ||
|
||
use messaging | ||
|
||
implicit none | ||
|
||
type(Messenger) :: hello, bye | ||
|
||
hello%message_ = 'Hello, CMake world!' | ||
print *, print_message(hello) | ||
|
||
bye%message_ = 'Bye, CMake world!' | ||
print *, print_message(bye) | ||
|
||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module messaging | ||
|
||
implicit none | ||
|
||
public Messenger | ||
type Messenger | ||
character(len=19) :: message_ | ||
end type | ||
|
||
public print_message | ||
|
||
private | ||
|
||
contains | ||
|
||
pure function print_message(postman) result(m) | ||
|
||
type(Messenger), intent(in) :: postman | ||
character(len=19) :: m | ||
|
||
m = postman%message_ | ||
|
||
end function | ||
|
||
end module |