Skip to content

Commit

Permalink
some reorganization
Browse files Browse the repository at this point in the history
add threadsafe to the pyf interfaces. i guess that is ok?
  • Loading branch information
jacobwilliams committed Feb 18, 2024
1 parent f6530aa commit 50b5cb3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
.DS_Store
/results.txt
/env
/build-python

# python
__pycache__
Expand Down
27 changes: 27 additions & 0 deletions build-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

#
# basic script to build a conda environment, build the python extension, and test it
#

rm -rf ./env
conda env create --prefix ./env -f ./python/environment.yml
conda activate ./env

cd python
chmod +x ./build_python.sh
./build_python.sh
cd ..

rm -rf ./build-python
mkdir ./build-python
mkdir ./build-python/radbeltpy

cp ./python/*.py ./build-python/radbeltpy
cp ./python/*.so ./build-python/radbeltpy
cp ./python/*.dll ./build-python/radbeltpy
cp ./python/*.dylib ./build-python/radbeltpy
cp -r data ./build-python/radbeltpy


python ./test/radbeltpy_test.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions radbeltpy/radbeltpy.pyf → python/radbeltpy.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python module radbelt_fortran ! in
use iso_c_binding, only: c_double,c_int,c_char,c_intptr_t

subroutine get_flux_g_c(ipointer,lon,lat,height,year,e,imname,flux) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(in) :: ipointer
real(c_double),intent(in) :: lon
real(c_double),intent(in) :: lat
Expand All @@ -18,18 +19,21 @@ python module radbelt_fortran ! in
end subroutine get_flux_g_c

subroutine set_trm_file_path_c(ipointer, aep8_dir, n) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(in) :: ipointer
character(kind=c_char,len=n),intent(in),depend(n) :: aep8_dir
integer(c_int),intent(in) :: n
end subroutine set_trm_file_path_c

subroutine set_igrf_file_path_c(ipointer, igrf_dir, n) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(in) :: ipointer
character(kind=c_char,len=n),intent(in),depend(n) :: igrf_dir
integer(c_int),intent(in) :: n
end subroutine set_igrf_file_path_c

subroutine set_data_files_paths_c(ipointer, aep8_dir, igrf_dir, n, m) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(in) :: ipointer
character(kind=c_char,len=n),intent(in),depend(n) :: aep8_dir
character(kind=c_char,len=m),intent(in),depend(m) :: igrf_dir
Expand All @@ -38,10 +42,12 @@ python module radbelt_fortran ! in
end subroutine set_data_files_paths_c

subroutine initialize_c(ipointer) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(out) :: ipointer
end subroutine initialize_c

subroutine destroy_c(ipointer) ! in :radbelt_fortran:radbelt_c_module.f90:radbelt_c_module
threadsafe
integer(c_intptr_t),intent(in) :: ipointer
end subroutine destroy_c

Expand Down
6 changes: 5 additions & 1 deletion src/shellig.f90
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ subroutine shellg(me, glat, glon, alt, dimo, fl, icode, b0, v)

associate (p => me%p)

radik = 0.0_wp ! to avoid -Wmaybe-uninitialized warnings

! convert to dipol-oriented co-ordinates
rq = 1.0_wp / (me%xi(1) * me%xi(1) + me%xi(2) * me%xi(2) + me%xi(3) * me%xi(3))
r3h = sqrt(rq * sqrt(rq))
Expand Down Expand Up @@ -521,7 +523,9 @@ subroutine shellg(me, glat, glon, alt, dimo, fl, icode, b0, v)
me%sp(1) = p(1, iequ - 1)
me%sp(2) = p(2, iequ - 1)
me%sp(3) = p(3, iequ - 1)
if (oradik >= 1.0e-15_wp) fi = fi + stp / 0.75_wp * oterm * oradik / (oradik - radik)
if (oradik >= 1.0e-15_wp) fi = fi + stp / &
0.75_wp * oterm * oradik / &
(oradik - radik)

! the minimal allowable value of fi was changed from 1e-15 to 1e-12,
! because 1e-38 is the minimal allowable arg. for alog in our envir.
Expand Down
15 changes: 0 additions & 15 deletions test.sh

This file was deleted.

2 changes: 1 addition & 1 deletion test/radbeltpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path

dir = Path(__file__).resolve().parents[1] # root directory
sys.path.insert(0,str(dir)) # assuming the radbelt lib is in python directory
sys.path.insert(0,str(dir / 'build-python')) # assuming the radbelt lib is in python directory
from radbeltpy import RadbeltClass # this is the module being tested

# location of the data files:
Expand Down

0 comments on commit 50b5cb3

Please sign in to comment.