-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f33944
commit 645141b
Showing
5 changed files
with
107 additions
and
57 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
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
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,32 @@ | ||
module util | ||
implicit none | ||
|
||
contains | ||
|
||
subroutine arange(a, b, dx, x) | ||
real(8), intent(in) :: a, b, dx | ||
real(8), dimension(:), intent(out) :: x | ||
|
||
integer :: i, n | ||
|
||
n = int((b - a) / dx) + 1 | ||
do i = 1, n | ||
x(i) = a + (i - 1) * dx | ||
end do | ||
end subroutine arange | ||
|
||
subroutine linspace(a, b, n, x) | ||
real(8), intent(in) :: a, b | ||
integer, intent(in) :: n | ||
real(8), dimension(:), intent(out) :: x | ||
|
||
real(8) :: dx | ||
integer :: i | ||
|
||
dx = (b - a) / (n - 1) | ||
do i = 1, n | ||
x(i) = a + (i - 1) * dx | ||
end do | ||
end subroutine linspace | ||
|
||
end module util |
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
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,31 @@ | ||
program test_interpolate | ||
implicit none | ||
|
||
call test_arange | ||
call test_linspace | ||
|
||
contains | ||
|
||
subroutine test_arange | ||
use util, only : arange | ||
|
||
real(8), dimension(5) :: expected, actual | ||
|
||
expected = (/ 0.0d0, 1.0d0, 2.0d0, 3.0d0, 4.0d0 /) | ||
call arange(0.0d0, 5.0d0, 1.0d0, actual) | ||
|
||
if (any(expected /= actual)) error stop | ||
end subroutine test_arange | ||
|
||
subroutine test_linspace | ||
use util, only : linspace | ||
|
||
real(8), dimension(5) :: expected, actual | ||
|
||
expected = (/ 0.0d0, 1.0d0, 2.0d0, 3.0d0, 4.0d0 /) | ||
call linspace(0.0d0, 4.0d0, 5, actual) | ||
|
||
if (any(expected /= actual)) error stop | ||
end subroutine test_linspace | ||
|
||
end program test_interpolate |