diff options
author | Christian C <cc@localhost> | 2024-11-11 12:29:32 -0800 |
---|---|---|
committer | Christian C <cc@localhost> | 2024-11-11 12:29:32 -0800 |
commit | b85ee9d64a536937912544c7bbd5b98b635b7e8d (patch) | |
tree | cef7bc17d7b29f40fc6b1867d0ce0a742d5583d0 /code/sunlab/fortran_src |
Initial commit
Diffstat (limited to 'code/sunlab/fortran_src')
-rw-r--r-- | code/sunlab/fortran_src/__init__.py | 1 | ||||
-rw-r--r-- | code/sunlab/fortran_src/fortran_library.f90 | 96 |
2 files changed, 97 insertions, 0 deletions
diff --git a/code/sunlab/fortran_src/__init__.py b/code/sunlab/fortran_src/__init__.py new file mode 100644 index 0000000..81bb83a --- /dev/null +++ b/code/sunlab/fortran_src/__init__.py @@ -0,0 +1 @@ +# f2py -c -m aae_flib_tfnb fortran_library.f90 --f90flags='-g -fimplicit-none -O3' diff --git a/code/sunlab/fortran_src/fortran_library.f90 b/code/sunlab/fortran_src/fortran_library.f90 new file mode 100644 index 0000000..d477995 --- /dev/null +++ b/code/sunlab/fortran_src/fortran_library.f90 @@ -0,0 +1,96 @@ +! fortran_library + +! Mean-Squared Displacement for a time lag `t` +function msd(a, t) result(b) + implicit none + + real(kind=8), intent(in) :: a(:,:) + integer(kind=8), intent(in) :: t + integer(kind=8) :: i, j + real(kind=8) :: s(size(a,1)-t, size(a,2)) + real(kind=8) :: b(size(a,1)-t) + + s(:, :) = a((t + 1):(size(a,1)), :) - a(1:(size(a,1)-t),:) + do i = 1, size(a, 1)-t + b(i) = 0.0 + do j = 1, size(a, 2) + b(i) = b(i) + s(i, j) ** 2 + end do + b(i) = sqrt(b(i)) + end do +end function msd + +! Mean-Squared Displacement for a time lag `t` +function mmsd(a, t) result(z) + implicit none + + real(kind=8), intent(in) :: a(:,:) + integer(kind=8), intent(in) :: t + integer(kind=8) :: i, j + real(kind=8) :: s(size(a,1)-t, size(a,2)) + real(kind=8) :: b(size(a,1)-t) + real(kind=8) :: z + + s(:, :) = a((t + 1):(size(a,1)), :) - a(1:(size(a,1)-t),:) + do i = 1, size(a, 1)-t + b(i) = 0.0 + do j = 1, size(a, 2) + b(i) = b(i) + s(i, j) ** 2 + end do + b(i) = sqrt(b(i)) + end do + z = sum(b(:)) / (size(b, 1)) +end function mmsd + +! Mean-Squared Displacement for time lags up to `T` +function msds(a, Ts) result(b) + implicit none + + real(kind=8), intent(in) :: a(:,:) + integer(kind=8), intent(in) :: Ts + integer(kind=8) :: i, j + integer(kind=8) :: t + real(kind=8) :: s(size(a,1), size(a,2)) + real(kind=8) :: b(size(a,1),Ts+1) + + do t = 0, Ts + s(:, :) = a((t + 1):(size(a,1)), :) - a(1:(size(a,1)-t),:) + do i = 1, size(a, 1) + b(i,t+1) = 0.0 + if (i <= size(a, 1) - t) then + do j = 1, size(a, 2) + b(i,t+1) = b(i,t+1) + s(i, j) ** 2 + end do + b(i,t+1) = sqrt(b(i,t+1)) + end if + end do + end do +end function msds + +! Mean-Squared Displacement for time lags up to `T` +! Return the mean for each time lag +function mmsds(a, Ts) result(z) + implicit none + + real(kind=8), intent(in) :: a(:,:) + integer(kind=8), intent(in) :: Ts + integer(kind=8) :: i, j + integer(kind=8) :: t + real(kind=8) :: s(size(a,1), size(a,2)) + real(kind=8) :: b(size(a,1),Ts+1) + real(kind=8) :: z(Ts+1) + + do t = 0, Ts + s(:, :) = a((t + 1):(size(a,1)), :) - a(1:(size(a,1)-t),:) + do i = 1, size(a, 1) + b(i,t+1) = 0.0 + if (i <= size(a, 1) - t) then + do j = 1, size(a, 2) + b(i,t+1) = b(i,t+1) + s(i, j) ** 2 + end do + b(i,t+1) = sqrt(b(i,t+1)) + end if + end do + z(t+1) = sum(b(1:(size(a, 1) - t),t+1)) / (size(a, 1) - t) + end do +end function mmsds |