45 REAL (rprec),
INTENT(in) :: x
46 REAL (rprec),
INTENT(out) :: y
47 REAL (rprec),
DIMENSION(:),
INTENT(in) :: xx
48 REAL (rprec),
DIMENSION(:),
INTENT(in) :: yy
49 INTEGER,
INTENT(in) :: n
52 INTEGER :: ilow, ihigh
57 stop
"Line sigments require at least two points"
58 ELSE IF (xx(1) .ge. xx(2))
THEN
59 stop
"Line sigments must be specified in increasing order of x"
63 IF (x .lt. xx(1))
THEN
65 ELSE IF (x .gt. xx(n))
THEN
66 ilow = n - 1; ihigh = n
71 y =
y_value(x, yy, xx, ilow, ihigh)
92 REAL (rprec),
INTENT(in) :: x
93 REAL (rprec),
INTENT(out) :: y
94 REAL (rprec),
DIMENSION(:),
INTENT(in) :: xx
95 REAL (rprec),
DIMENSION(:),
INTENT(in) :: yy
96 INTEGER,
INTENT(in) :: n
99 INTEGER :: ilow, ihigh
100 INTEGER :: i0low, i0high
106 stop
"Line sigments require at least two points"
107 ELSE IF (xx(1) .ge. xx(2))
THEN
108 stop
"Line sigments must be specified in increasing order of x"
112 IF (x .lt. xx(1))
THEN
114 ELSE IF (x .gt. xx(n))
THEN
115 ilow = n - 1; ihigh = n
121 IF (zero .lt. xx(1))
THEN
122 i0low = 1; i0high = 2
123 ELSE IF (zero .gt. xx(n))
THEN
124 i0low = n - 1; i0high = n
132 IF (ilow .eq. i0low)
THEN
135 y =
y_value_int(zero, xx(i0high), yy, xx, i0low, i0high)
136 DO i = i0high, ilow - 1
137 y = y +
y_value_int(xx(i), xx(i+1), yy, xx, i, i+1)
139 y = y +
y_value_int(xx(ilow), x, yy, xx, ilow, ihigh)
164 &
SUBROUTINE get_indices(x, xx, lBound, uBound, ilow, ihigh)
169 REAL(rprec),
INTENT(in) :: x
170 REAL(rprec),
DIMENSION(:),
INTENT(in) :: xx
171 INTEGER,
INTENT(in) :: lbound
172 INTEGER,
INTENT(in) :: ubound
173 INTEGER,
INTENT(out) :: ilow
174 INTEGER,
INTENT(out) :: ihigh
185 IF (ubound - lbound .eq. 1)
THEN
186 ilow = lbound; ihigh = ubound
190 hbound = (ubound + lbound)/2
191 IF (x .ge. xx(lbound) .and. x .lt. xx(hbound))
THEN
192 CALL get_indices(x, xx, lbound, hbound, ilow, ihigh)
194 CALL get_indices(x, xx, hbound, ubound, ilow, ihigh)
210 PURE FUNCTION slope(yy, xx, ilow, ihigh)
216 REAL(rprec),
DIMENSION(:),
INTENT(in) :: xx
217 REAL(rprec),
DIMENSION(:),
INTENT(in) :: yy
218 INTEGER,
INTENT(in) :: ilow
219 INTEGER,
INTENT(in) :: ihigh
222 slope = (yy(ihigh) - yy(ilow))/(xx(ihigh) - xx(ilow))
238 PURE FUNCTION offset(yy, xx, ilow, ihigh)
244 REAL(rprec),
DIMENSION(:),
INTENT(in) :: xx
245 REAL(rprec),
DIMENSION(:),
INTENT(in) :: yy
246 INTEGER,
INTENT(in) :: ilow
247 INTEGER,
INTENT(in) :: ihigh
250 offset = (xx(ihigh)*yy(ilow) - xx(ilow)*yy(ihigh))
251 & / (xx(ihigh) - xx(ilow))
269 PURE FUNCTION y_value(x, yy, xx, ilow, ihigh)
275 REAL(rprec),
INTENT(in) :: x
276 REAL(rprec),
DIMENSION(:),
INTENT(in) :: xx
277 REAL(rprec),
DIMENSION(:),
INTENT(in) :: yy
278 INTEGER,
INTENT(in) :: ilow
279 INTEGER,
INTENT(in) :: ihigh
282 IF (xx(ilow) .eq. xx(ihigh))
THEN
286 & +
offset(yy, xx, ilow, ihigh)
306 PURE FUNCTION y_value_int(x0, x1, yy, xx, ilow, ihigh)
312 REAL(rprec),
INTENT(in) :: x0
313 REAL(rprec),
INTENT(in) :: x1
314 REAL(rprec),
DIMENSION(:),
INTENT(in) :: xx
315 REAL(rprec),
DIMENSION(:),
INTENT(in) :: yy
316 INTEGER,
INTENT(in) :: ilow
317 INTEGER,
INTENT(in) :: ihigh
320 IF (xx(ilow) .eq. xx(ihigh))
THEN
324 & / 2.0*(x1**2.0 - x0**2.0)
325 & +
offset(yy, xx, ilow, ihigh)*(x1 - x0)
351 REAL(rprec) :: result
355 result =
slope((/ 0.0d+0, 1.0d+0 /),
356 & (/ 0.0d+0, 1.0d+0 /),
361 result =
slope((/ 1.0d+0, 0.0d+0 /),
362 & (/ 0.0d+0, 1.0d+0 /),
367 result =
slope((/ 1.0d+0, 1.0d+0 /),
368 & (/ 0.0d+0, 1.0d+0 /),
374 result =
slope((/ 0.0d+0, 1.0d+0 /),
375 & (/ 1.0d+0, 2.0d+0 /),
380 result =
offset((/ 0.0d+0, 1.0d+0 /),
381 & (/ 0.0d+0, 1.0d+0 /),
386 result =
offset((/ 1.0d+0, 0.0d+0 /),
387 & (/ 0.0d+0, 1.0d+0 /),
392 result =
offset((/ 2.0d+0, 1.0d+0 /),
393 & (/ 1.0d+0, 2.0d+0 /),
401 & (/ 0.0d+0, 2.0d+0 /),
402 & (/ 0.0d+0, 2.0d+0 /),
409 & (/ 1.0d+0, 2.0d+0 /),
410 & (/ 1.0d+0, 2.0d+0 /),
417 & (/ 0.0d+0, 1.0d+0 /),
418 & (/ 0.0d+0, 1.0d+0 /),
426 & (/ 1.0d+0, 1.0d+0 /),
427 & (/ 0.0d+0, 1.0d+0 /),
435 & (/ 1.0d+0, 1.0d+0 /),
436 & (/ 1.0d+0, 2.0d+0 /),
443 & (/ 1.0d+0, 1.0d+0 /),
444 & (/ 0.0d+0, 1.0d+0 /),
451 & (/ 0.0d+0, 1.0d+0 /),
452 & (/ 0.0d+0, 1.0d+0 /),
459 & (/ 1.0d+0, 2.0d+0 /),
460 & (/ 0.0d+0, 1.0d+0 /),
467 & (/ 1.0d+0, 2.0d+0 /),
468 & (/ 1.0d+0, 2.0d+0 /),
475 & (/ 1.0d+0, 2.0d+0 /),
476 & (/ 1.0d+0, 2.0d+0 /),
484 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
485 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
492 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
493 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
500 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
501 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
508 & (/ 1.0d+0, 2.0d+0, 3.0d+0, 4.0d+0 /),
509 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
516 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
517 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
525 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
526 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
533 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
534 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
541 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
542 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
549 & (/ 1.0d+0, 2.0d+0, 3.0d+0, 4.0d+0 /),
550 & (/ 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0 /),
557 & (/ 0.0d+0, 1.0d+0, 2.0d+0, 3.0d+0 /),
558 & (/ 1.0d+0, 0.0d+0, 0.0d+0, 1.0d+0 /),
565 & (/ 1.0d+0, 2.0d+0, 3.0d+0, 4.0d+0 /),
566 & (/ 1.0d+0, 0.0d+0, 0.0d+0, 1.0d+0 /),
588 FUNCTION check(expected, received, testNum, name)
594 REAL(rprec),
INTENT(in) :: expected
595 REAL(rprec),
INTENT(in) :: received
596 INTEGER,
INTENT(in) :: testnum
597 CHARACTER (LEN=*),
INTENT(in) :: name
600 check = expected .eq. received
602 WRITE(*,*)
"line_segment_mod.f: ", name,
" test", testnum,
604 WRITE(*,*)
"Expected", expected,
"Received", received