Skip to content

Commit fa1d59d

Browse files
committed
Added clause in ipos() for when x == xmax
1 parent 73c9e0d commit fa1d59d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/lib_array.f90

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! MD5 of template: 874b367ed9a2602d10f066584f750d00
1+
! MD5 of template: 712f522020dbe2eab390eba5980d46a1
22
! Array related routines (Integration, Interpolation, etc.)
33
! Thomas Robitaille (c) 2009
44

@@ -853,9 +853,11 @@ integer function ipos_dp(xmin,xmax,x,nbin)
853853
ipos_dp = 0
854854
else if(x > xmax) then
855855
ipos_dp = nbin+1
856-
else
856+
else if(x < xmax) then
857857
frac=(x-xmin)/(xmax-xmin)
858-
ipos_dp=int(frac*real(nbin))+1
858+
ipos_dp=int(frac*real(nbin, dp))+1
859+
else ! x == xmax
860+
ipos_dp = nbin
859861
end if
860862

861863
else
@@ -864,9 +866,11 @@ integer function ipos_dp(xmin,xmax,x,nbin)
864866
ipos_dp = 0
865867
else if(x > xmin) then
866868
ipos_dp = nbin+1
867-
else
869+
else if(x < xmin) then
868870
frac=(x-xmin)/(xmax-xmin)
869-
ipos_dp=int(frac*real(nbin))+1
871+
ipos_dp=int(frac*real(nbin, dp))+1
872+
else ! x == xmin
873+
ipos_dp = nbin
870874
end if
871875

872876
end if
@@ -1801,9 +1805,11 @@ integer function ipos_sp(xmin,xmax,x,nbin)
18011805
ipos_sp = 0
18021806
else if(x > xmax) then
18031807
ipos_sp = nbin+1
1804-
else
1808+
else if(x < xmax) then
18051809
frac=(x-xmin)/(xmax-xmin)
1806-
ipos_sp=int(frac*real(nbin))+1
1810+
ipos_sp=int(frac*real(nbin, sp))+1
1811+
else ! x == xmax
1812+
ipos_sp = nbin
18071813
end if
18081814

18091815
else
@@ -1812,9 +1818,11 @@ integer function ipos_sp(xmin,xmax,x,nbin)
18121818
ipos_sp = 0
18131819
else if(x > xmin) then
18141820
ipos_sp = nbin+1
1815-
else
1821+
else if(x < xmin) then
18161822
frac=(x-xmin)/(xmax-xmin)
1817-
ipos_sp=int(frac*real(nbin))+1
1823+
ipos_sp=int(frac*real(nbin, sp))+1
1824+
else ! x == xmin
1825+
ipos_sp = nbin
18181826
end if
18191827

18201828
end if

templates/lib_array_template.f90

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,11 @@ integer function ipos_<T>(xmin,xmax,x,nbin)
834834
ipos_<T> = 0
835835
else if(x > xmax) then
836836
ipos_<T> = nbin+1
837-
else
837+
else if(x < xmax) then
838838
frac=(x-xmin)/(xmax-xmin)
839-
ipos_<T>=int(frac*real(nbin))+1
839+
ipos_<T>=int(frac*real(nbin, <T>))+1
840+
else ! x == xmax
841+
ipos_<T> = nbin
840842
end if
841843

842844
else
@@ -845,9 +847,11 @@ integer function ipos_<T>(xmin,xmax,x,nbin)
845847
ipos_<T> = 0
846848
else if(x > xmin) then
847849
ipos_<T> = nbin+1
848-
else
850+
else if(x < xmin) then
849851
frac=(x-xmin)/(xmax-xmin)
850-
ipos_<T>=int(frac*real(nbin))+1
852+
ipos_<T>=int(frac*real(nbin, <T>))+1
853+
else ! x == xmin
854+
ipos_<T> = nbin
851855
end if
852856

853857
end if

0 commit comments

Comments
 (0)