Skip to content

Commit

Permalink
fix in datetimeRange to avoid round-off error
Browse files Browse the repository at this point in the history
  • Loading branch information
milancurcic committed Dec 14, 2014
1 parent 212a8a8 commit 4c0161f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions datetime.f90
Expand Up @@ -18,9 +18,9 @@
MODULE datetime_module
!======================================================================>
!
! VERSION: 1.0.5
! VERSION: 1.0.6
!
! LAST UPDATE: 2014-11-01
! LAST UPDATE: 2014-12-13
!
! AUTHOR: Milan Curcic
! University of Miami
Expand Down Expand Up @@ -1544,17 +1544,20 @@ PURE FUNCTION datetimeRange(d0,d1,t)
TYPE(timedelta),INTENT(IN) :: t

REAL(KIND=real_dp) :: datenum0,datenum1,increment
REAL(KIND=real_dp) :: eps

TYPE(datetime),DIMENSION(:),ALLOCATABLE :: datetimeRange

INTEGER :: n,nm

eps = 1e-10_real_dp

datenum0 = date2num(d0)
datenum1 = date2num(d1)

increment = t % total_seconds() * s2d

nm = FLOOR((datenum1-datenum0)/increment)+1
nm = FLOOR((datenum1-datenum0+eps)/increment)+1

ALLOCATE(datetimeRange(nm))

Expand Down

0 comments on commit 4c0161f

Please sign in to comment.