diff --git a/.gitignore b/.gitignore index 570d0b3..ce1bf51 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ .DS_Store /results.txt /env +/build-python # python __pycache__ diff --git a/build-python.sh b/build-python.sh new file mode 100755 index 0000000..f259ec4 --- /dev/null +++ b/build-python.sh @@ -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 diff --git a/radbeltpy/.f2py_f2cmap b/python/.f2py_f2cmap similarity index 100% rename from radbeltpy/.f2py_f2cmap rename to python/.f2py_f2cmap diff --git a/radbeltpy/__init__.py b/python/__init__.py similarity index 100% rename from radbeltpy/__init__.py rename to python/__init__.py diff --git a/radbeltpy/build_python.sh b/python/build_python.sh similarity index 100% rename from radbeltpy/build_python.sh rename to python/build_python.sh diff --git a/radbeltpy/environment.yml b/python/environment.yml similarity index 100% rename from radbeltpy/environment.yml rename to python/environment.yml diff --git a/radbeltpy/radbeltpy.pyf b/python/radbeltpy.pyf similarity index 94% rename from radbeltpy/radbeltpy.pyf rename to python/radbeltpy.pyf index 7f5d7b2..46fb93d 100644 --- a/radbeltpy/radbeltpy.pyf +++ b/python/radbeltpy.pyf @@ -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 @@ -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 @@ -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 diff --git a/src/shellig.f90 b/src/shellig.f90 index 232016a..81e68ca 100644 --- a/src/shellig.f90 +++ b/src/shellig.f90 @@ -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)) @@ -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. diff --git a/test.sh b/test.sh deleted file mode 100755 index 1baefe6..0000000 --- a/test.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/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 radbeltpy -chmod +x ./build_python.sh -./build_python.sh -cd .. -python ./test/radbeltpy_test.py diff --git a/test/radbeltpy_test.py b/test/radbeltpy_test.py index 03ecf86..70463b4 100644 --- a/test/radbeltpy_test.py +++ b/test/radbeltpy_test.py @@ -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: