Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Improved the tslot finder using proper ieee arithmetic routine
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed May 25, 2023
1 parent 511e425 commit d854c21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SET(STRICT_MATH_FILES
${SRC}/helio/helio_step.f90
${SRC}/misc/lambda_function_module.f90
${SRC}/misc/solver_module.f90
${SRC}/netcdf_io/netcdf_io_implementations.f90
${SRC}/operator/operator_module.f90
${SRC}/operator/operator_cross.f90
${SRC}/operator/operator_mag.f90
Expand Down Expand Up @@ -69,7 +70,6 @@ SET(FAST_MATH_FILES
${SRC}/encounter/encounter_io.f90
${SRC}/encounter/encounter_util.f90
${SRC}/helio/helio_util.f90
${SRC}/netcdf_io/netcdf_io_implementations.f90
${SRC}/rmvs/rmvs_discard.f90
${SRC}/rmvs/rmvs_encounter_check.f90
${SRC}/rmvs/rmvs_util.f90
Expand Down
9 changes: 8 additions & 1 deletion src/netcdf_io/netcdf_io_implementations.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module subroutine netcdf_io_find_tslot(self, t, tslot)
!!
!! Given an open NetCDF file and a value of time t, finds the index of the time value (aka the time slot) to place a new set of data.
!! The returned value of tslot will correspond to the first index value where the value of t is greater than or equal to the saved time value.
use, intrinsic :: ieee_exceptions
use, intrinsic :: ieee_arithmetic
implicit none
! Arguments
class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset
Expand All @@ -67,7 +69,10 @@ module subroutine netcdf_io_find_tslot(self, t, tslot)
! Internals
real(DP), dimension(:), allocatable :: tvals
integer(I4B) :: i
logical, dimension(size(IEEE_ALL)) :: fpe_halting_modes

call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily
call ieee_set_halting_mode(IEEE_ALL,.false.)

if (.not.self%lfile_is_open) return
tslot = 0
Expand All @@ -76,7 +81,7 @@ module subroutine netcdf_io_find_tslot(self, t, tslot)
if (self%max_tslot > 0) then
allocate(tvals(self%max_tslot))
call netcdf_io_check( nf90_get_var(self%id, self%time_varid, tvals(:), start=[1]), "netcdf_io_find_tslot get_var" )
where(tvals(:) /= tvals(:)) tvals(:) = huge(1.0_DP)
where(.not.ieee_is_normal(tvals(:))) tvals(:) = huge(1.0_DP)
else
allocate(tvals(1))
tvals(1) = huge(1.0_DP)
Expand All @@ -91,6 +96,8 @@ module subroutine netcdf_io_find_tslot(self, t, tslot)
self%max_tslot = max(self%max_tslot, tslot)
self%tslot = tslot

call ieee_set_halting_mode(IEEE_ALL,fpe_halting_modes)

return
end subroutine netcdf_io_find_tslot

Expand Down

0 comments on commit d854c21

Please sign in to comment.