52 real(rprec),
parameter :: one=1, zero=0, p5=0.5_dp
53 integer,
parameter :: idebug = 0
80 public dbsint, dbsval, dbsder, dbs1gd
81 public dbs2in, dbs2dr, dbs2vl, dbs2gd
82 public dbs3in, dbs3vl, dbs3dr, dbs3gd
89 subroutine dbsnak(nx,xvec,kxord,xknot)
104 integer,
intent(in) :: nx, kxord
106 real(rprec),
dimension(nx),
intent(in) :: xvec
107 real(rprec),
dimension(nx+kxord),
intent(out) :: xknot
111 logical :: first = .true.
124 if((kxord .lt. 0) .or. (kxord .gt. nx))
then
125 write(6,*)
"subroutine dbsnak: error"
126 write(6,*)
"0 <= kxord <= nx is required."
127 write(6,*)
"kxord = ", kxord,
" and nx = ", nx,
" is given."
135 if(mod(kxord,2) .eq. 0)
then
137 xknot(ix) = xvec(ix-kxord/2)
141 xknot(ix) = p5 * (xvec(ix-kxord/2) + xvec(ix-kxord/2-1))
145 do ix = nx+1, nx+kxord
146 xknot(ix) = xvec(nx) * (one + eps)
149 end subroutine dbsnak
152 subroutine dbsint(nx,xvec,xdata,kx,xknot,bcoef)
174 integer,
intent(in) :: nx, kx
175 real(rprec),
dimension(nx),
intent(in) :: xdata, xvec
176 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
177 real(rprec),
dimension(nx),
intent(out) :: bcoef
179 integer :: nxp1, kxm1, kpkm2, leftx, lenq
180 integer :: ix, ik,ilp1mx, jj, iflag
182 real(rprec),
dimension((2*kx-1)*nx) :: work
189 lenq = nx * (kx + kxm1)
197 ilp1mx = min(ix+kx,nxp1)
198 leftx = max(leftx,ix)
199 if (xveci .lt. xknot(leftx))
goto 998
200 30
if (xveci .lt. xknot(leftx+1))
go to 40
202 if (leftx .lt. ilp1mx)
go to 30
204 if (xveci .gt. xknot(leftx+1))
goto 998
205 40
call bsplvb (xknot,nx+kx,kx,1,xveci,leftx,bcoef)
206 jj = ix - leftx + 1 + (leftx - kx) * (kx + kxm1)
213 call banfac(work,kx+kxm1,nx,kxm1,kxm1,iflag)
215 if (iflag .ne. 1)
then
216 write(6,*)
"subroutine dbsint: error"
217 write(6,*)
"no solution of linear equation system !!!"
222 bcoef(ix) = xdata(ix)
225 call banslv(work,kx+kxm1,nx,kxm1,kxm1,bcoef)
229 998
write(6,*)
"subroutine dbsint:"
230 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
231 write(6,*) ix,xknot(ix),xknot(ix+1)
235 end subroutine dbsint
238 function dbsval(x,kx,xknot,nx,bcoef)
256 integer,
intent(in) :: nx, kx
257 real(rprec) :: dbsval
259 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
260 real(rprec),
dimension(nx),
intent(in) :: bcoef
262 integer :: il, ik, ix, leftx
263 real(rprec) :: save1, save2
264 real(rprec),
dimension(kx) :: work, dl, dr
274 if (xknot(ix) .gt. xknot(ix+1))
then
275 write(6,*)
"subroutine dbsval:"
276 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
277 write(6,*) ix,xknot(ix),xknot(ix+1)
280 if((xknot(ix) .le. x) .and. (x .lt. xknot(ix+1))) leftx = ix
283 if(leftx .eq. 0)
then
284 write(6,*)
"subroutine dbsval:"
285 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
291 work(ik) = bcoef(leftx+ik-kx)
292 dl(ik) = x - xknot(leftx+ik-kx)
293 dr(ik) = xknot(leftx+ik) - x
296 work(kx) = bcoef(leftx)
297 dl(kx) = x - xknot(leftx)
303 work(il) = (dl(il) * work(il) + dr(il-ik) * save2) &
304 & / (dl(il) + dr(il - ik))
314 function dbsder(iderx,x,kx,xknot,nx,bcoef)
337 integer,
intent(in) :: iderx, kx, nx
338 real(rprec) :: dbsder
339 real(rprec),
intent(in) :: x
340 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
341 real(rprec),
dimension(nx),
intent(in) :: bcoef
343 integer :: ix, ik, il, leftx
344 real(rprec) :: save0, save1, save2, y, sum, dik
345 real(rprec),
dimension(kx) :: work, dl, dr,bsp
354 if (xknot(ix) .gt. xknot(ix+1))
then
355 write(6,*)
"subroutine dbsder:"
356 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
359 if ((xknot(ix) .le. x) .and. (x .lt. xknot(ix+1))) leftx = ix
362 if (leftx .eq. 0)
then
363 write(6,*)
"subroutine dbsder:"
364 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
365 write(6,*)
"xknot(1) = ", xknot(1)
366 write(6,*)
"xknot(nx+kx) = ", xknot(nx+kx)
367 write(6,*)
" x = ", x
371 if (iderx .eq. 0)
then
374 work(ik) = bcoef(leftx+ik-kx)
375 dl(ik) = x - xknot(leftx+ik-kx)
376 dr(ik) = xknot(leftx+ik) - x
379 work(kx) = bcoef(leftx)
380 dl(kx) = x - xknot(leftx)
386 work(il) = (dl(il) * work(il) + dr(il-ik) * save2) &
387 & / (dl(il) + dr(il - ik))
394 elseif ((iderx .ge. 1) .and. (iderx .lt. kx))
then
398 dr(ik) = xknot(leftx+ik) - x
399 dl(ik) = x - xknot(leftx+1-ik)
403 y = save0 / (dr(il) + dl(ik+1-il))
404 bsp(il) = bsp(il) + dr(il) * y
406 bsp(il+1) = dl(ik+1-il) * y
411 work(ik) = bcoef(leftx+ik-kx)
412 dr(ik) = xknot(leftx+ik) - x
413 dl(ik) = x - xknot(leftx+ik-kx)
417 dik = real(kx - ik, kind=dp)
421 work(il) = dik * (work(il) - save2) /(dl(il) + dr(il-ik))
429 sum = sum + bsp(ix) * work(iderx+ix)
441 subroutine dbs1gd(iderx,nxvec,xvec,kx,xknot,nx,bcoef,val)
468 integer,
intent(in) :: iderx, nxvec, kx, nx
469 real(rprec),
dimension(nxvec),
intent(in) :: xvec
470 real(rprec),
dimension(nx),
intent(in) :: bcoef
471 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
472 real(rprec),
dimension(nxvec),
intent(out) :: val
474 integer :: i, il, ik, ix
475 integer,
dimension(nxvec) :: leftx
477 real(rprec),
dimension(nxvec,kx) :: dl, dr, biatx, work
478 real(rprec),
dimension(nxvec) :: save1, save2, term
480 logical :: same, next
485 call huntn(xknot,nx+kx,kx,xvec(1),leftx(1))
488 leftx(ix) = leftx(ix-1)
489 same = (xknot(leftx(ix)) .le. xvec(ix)) &
490 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
492 leftx(ix) = leftx(ix) + 1
493 next = (xknot(leftx(ix)) .le. xvec(ix)) &
494 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
496 &
call huntn(xknot,nx+kx,kx,xvec(ix),leftx(ix))
501 if (xknot(ix) .gt. xknot(ix+1))
then
502 write(6,*)
"subroutine dbs1gd:"
503 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
504 write(6,*) ix, xknot(ix), xknot(ix+1)
512 if ((xvec(ix).lt.xknot(1)).or.(xvec(ix).gt.xknot(nx+kx)))
then
513 write(6,*)
"subroutine dbs1gd:"
514 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
515 write(6,*)
"x = ", xvec(ix)
520 if (iderx .eq. 0)
then
529 dr(ix,ik) = xknot(leftx(ix)+ik) - xvec(ix)
530 dl(ix,ik) = xvec(ix) - xknot(leftx(ix)+1-ik)
536 term(ix) = biatx(ix,il) &
537 & / (dr(ix,il) + dl(ix,ik+1-il))
538 biatx(ix,il) = save1(ix) + dr(ix,il) * term(ix)
539 save1(ix) = dl(ix,ik+1-il) * term(ix)
544 biatx(ix,ik+1) = save1(ix)
550 val(ix) = val(ix) + biatx(ix,ik) * bcoef(leftx(ix)-kx+ik)
554 elseif ((iderx .ge. 1) .and. (iderx .lt. kx))
then
561 do ik = 1, kx-iderx-1
563 dr(ix,ik) = xknot(leftx(ix)+ik) - xvec(ix)
564 dl(ix,ik) = xvec(ix) - xknot(leftx(ix)+1-ik)
565 save1(ix) = biatx(ix,1)
568 term(ix) = save1(ix) &
569 & / (dr(ix,il) + dl(ix,ik+1-il))
570 biatx(ix,il) = biatx(ix,il) + dr(ix,il) * term(ix)
571 save1(ix) = biatx(ix,il+1)
572 biatx(ix,il+1) = dl(ix,ik+1-il) * term(ix)
579 work(ix,ik) = bcoef(leftx(ix)+ik-kx)
580 dr(ix,ik) = xknot(leftx(ix)+ik) - xvec(ix)
581 dl(ix,ik) = xvec(ix) - xknot(leftx(ix)+ik-kx)
586 dik = real(kx-ik, kind=rprec)
588 save2(ix) = work(ix,ik)
590 save1(ix) = work(ix,il)
591 work(ix,il) = dik * (work(ix,il) - save2(ix)) &
592 & /(dl(ix,il) + dr(ix,il-ik))
593 save2(ix) = save1(ix)
600 val(ix) = val(ix) + biatx(ix,i) * work(ix,iderx+i)
612 end subroutine dbs1gd
615 function dbsdca(iderx,x,kx,xknot,nx,bcoef,leftx)
642 integer,
intent(in) :: iderx, kx, nx
643 real(rprec) :: dbsdca
644 real(rprec),
intent(in) :: x
645 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
646 real(rprec),
dimension(nx),
intent(in) :: bcoef
648 integer :: i, ik, il, leftx
649 real(rprec) :: save0, save1, save2, y, sum, dik
650 real(rprec),
dimension(kx) :: work, dl, dr,bsp
653 if (iderx .eq. 0)
then
656 work(ik) = bcoef(leftx+ik-kx)
657 dl(ik) = x - xknot(leftx+ik-kx)
658 dr(ik) = xknot(leftx+ik) - x
661 work(kx) = bcoef(leftx)
662 dl(kx) = x - xknot(leftx)
668 work(il) = (dl(il) * work(il) + dr(il-ik) * save2) &
669 & / (dl(il) + dr(il - ik))
676 elseif ((iderx .ge. 1) .and. (iderx .lt. kx))
then
679 dr(ik) = xknot(leftx+ik) - x
680 dl(ik) = x - xknot(leftx+1-ik)
684 y = save0 / (dr(il) + dl(ik+1-il))
685 bsp(il) = bsp(il) + dr(il) * y
687 bsp(il+1) = dl(ik+1-il) * y
692 work(ik) = bcoef(leftx+ik-kx)
693 dr(ik) = xknot(leftx+ik) - x
694 dl(ik) = x - xknot(leftx+ik-kx)
698 dik = real(kx - ik, kind=rprec)
702 work(il) = dik * (work(il) - save2) /(dl(il) + dr(il-ik))
710 sum = sum + bsp(i) * work(iderx+i)
722 subroutine dbs2in(nx,xvec,ny,yvec,xydata,ldf,kx,ky,xknot,yknot,bcoef)
760 integer,
intent(in) :: nx, ny, kx, ky, ldf
762 real(rprec),
dimension(nx),
intent(in) :: xvec
763 real(rprec),
dimension(ny),
intent(in) :: yvec
764 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
765 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
766 real(rprec),
dimension(ldf,*),
intent(in) :: xydata
767 real(rprec),
dimension(nx,ny),
intent(out) :: bcoef
769 real(rprec),
dimension(max(nx,ny),max(nx,ny)) :: work1
770 real(rprec),
dimension(max(nx,ny)) :: work2
771 real(rprec),
dimension(max((2*kx-1)*nx,(2*ky-1)*ny)) :: work3
774 call spli2d(xvec,ldf,xydata,xknot,nx,kx,ny,work2,work3,work1)
775 call spli2d(yvec,ny, work1, yknot,ny,ky,nx,work2,work3,bcoef)
777 end subroutine dbs2in
780 subroutine spli2d(xyvec,ld,xydata,xyknot,n,k,m,work2,work3,bcoef)
785 integer,
intent(in) :: ld, n, k, m
786 real(rprec),
dimension(n),
intent(in) :: xyvec
787 real(rprec),
dimension(n+k),
intent(in) :: xyknot
788 real(rprec),
dimension(ld,m),
intent(in) :: xydata
789 real(rprec),
dimension(m,n),
intent(out) :: bcoef
791 real(rprec),
dimension(n),
intent(out) :: work2
792 real(rprec),
dimension((2*k-1)*n),
intent(out) :: work3
795 integer :: np1, km1, kpkm2, left, lenq, i, iflag, ilp1mx, j, jj
796 real(rprec) :: xyveci
810 ilp1mx = min(i+k,np1)
812 if (xyveci .lt. xyknot(left))
go to 998
813 30
if (xyveci .lt. xyknot(left+1))
go to 40
815 if (left .lt. ilp1mx)
go to 30
817 if (xyveci .gt. xyknot(left+1))
go to 998
818 40
call bsplvb(xyknot,n+k,k,1,xyveci,left,work2)
819 jj = i - left + 1 + (left - k) * (k + km1)
826 call banfac(work3,k+km1,n,km1,km1,iflag )
828 if (iflag .ne. 1)
then
829 write(6,*)
"subroutine dbs2in: error"
830 write(6,*)
"no solution of linear equation system !!!"
836 work2(i) = xydata(i,j)
839 call banslv(work3,k+km1,n,km1,km1,work2)
842 bcoef(j,i) = work2(i)
848 998
write(6,*)
"subroutine db2in:"
849 write(6,*)
"i with knot(i) <= x/y < knot(i+1) required."
850 write(6,*)
"knot(1) = ", xyknot(1)
851 write(6,*)
"knot(n+k) = ", xyknot(n+k)
852 write(6,*)
" x/y = ", xyveci
856 end subroutine spli2d
859 function dbs2vl(x,y,kx,ky,xknot,yknot,nx,ny,bcoef)
890 integer,
intent(in) :: nx, ny, kx, ky
891 real(rprec),
intent(in) :: x, y
892 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
893 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
894 real(rprec),
dimension(nx,ny),
intent(in) :: bcoef
895 real(rprec) :: dbs2vl
897 integer :: ix, iy, iky, leftx, lefty
898 real(rprec),
dimension(ky) :: work
908 if (xknot(ix) .gt. xknot(ix+1))
then
909 write(6,*)
"subroutine dbs2vl:"
910 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
911 write(6,*) ix, xknot(ix), xknot(ix+1)
916 if((xknot(ix) .le. x) .and. (x .lt. xknot(ix+1))) leftx = ix
919 if(leftx .eq. 0)
then
920 write(6,*)
"subroutine dbs2vl:"
921 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
931 if (yknot(iy) .gt. yknot(iy+1))
then
932 write(6,*)
"subroutine dbs2vl:"
933 write(6,*)
"yknot(iy) <= yknot(iy+1) required."
934 write(6,*) iy, yknot(iy), yknot(iy+1)
937 if((yknot(iy) .le. y) .and. (y .lt. yknot(iy+1))) lefty = iy
940 if(lefty .eq. 0)
then
941 write(6,*)
"subroutine dbs2vl:"
942 write(6,*)
"iy with yknot(iy) <= y < yknot(iy+1) required."
943 write(6,*)
"yknot(iy) = ", yknot(iy)
944 write(6,*)
" y = ", y
945 write(6,*)
"yknot(iy+1) = ", yknot(iy+1)
950 work(iky) = dbsdca(0,x,kx,xknot,nx,bcoef(1,lefty-ky+iky),leftx)
953 dbs2vl = dbsval(y,ky,yknot(lefty-ky+1),ky,work)
958 function dbs2dr(iderx,idery,x,y,kx,ky,xknot,yknot,nx,ny,bcoef)
992 integer,
intent(in) :: iderx, idery
993 integer,
intent(in) :: kx, nx, ky, ny
994 real(rprec) :: dbs2dr
995 real(rprec),
intent(in) :: x, y
996 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
997 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
998 real(rprec),
dimension(nx,ny),
intent(in) :: bcoef
1000 integer :: ix, iy, iky, nintx, ninty
1001 real(rprec),
dimension(ky) :: work
1011 if (xknot(ix) .gt. xknot(ix+1))
then
1012 write(6,*)
"subroutine dbs2dr:"
1013 write(6,*)
"xknot(ix) <= xknot(ix+1) required."
1014 write(6,*) ix, xknot(ix), xknot(ix+1)
1017 if((xknot(ix) .le. x) .and. (x .lt. xknot(ix+1))) nintx = ix
1020 if(nintx .eq. 0)
then
1021 write(6,*)
"subroutine dbs2dr:"
1022 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
1023 write(6,*)
"x = ", x
1030 if (yknot(iy) .gt. yknot(iy+1))
then
1031 write(6,*)
"subroutine dbs2dr:"
1032 write(6,*)
"yknot(iy) <= yknot(iy+1) required."
1033 write(6,*) iy, yknot(iy), yknot(iy+1)
1036 if ((yknot(iy) .le. y) .and. (y .lt. yknot(iy+1))) ninty = iy
1039 if(ninty .eq. 0)
then
1040 write(6,*)
"subroutine dbs2dr:"
1041 write(6,*)
"iy with yknot(iy) <= y < yknot(iy+1) required."
1042 write(6,*)
"y = ", y
1047 work(iky) = dbsdca(iderx,x,kx,xknot,nx,bcoef(1,ninty-ky+iky),nintx)
1050 dbs2dr = dbsder(idery,y,ky,yknot(ninty-ky+1),ky,work)
1055 subroutine dbs2gd(iderx,idery,nxvec,xvec,nyvec,yvec,kx,ky,xknot,yknot, &
1056 & nx,ny,bcoef,val,ldf)
1098 integer,
intent(in) :: iderx, idery
1099 integer,
intent(in) :: nxvec, nyvec
1100 integer,
intent(in) :: kx, nx, ky, ny
1101 integer,
intent(in) :: ldf
1103 real(rprec),
dimension(nxvec),
intent(in) :: xvec
1104 real(rprec),
dimension(nyvec),
intent(in) :: yvec
1105 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
1106 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
1107 real(rprec),
dimension(nx,ny),
intent(in) :: bcoef
1108 real(rprec),
dimension(ldf,*),
intent(out) :: val
1110 integer :: i, ik, il, ix, iy, ikx, iky
1111 integer,
dimension(nxvec) :: leftx
1112 integer,
dimension(nyvec) :: lefty
1113 real(rprec),
dimension(nxvec,kx) :: dl, dr
1114 real(rprec),
dimension(max(nxvec,nyvec)) :: save1
1115 real(rprec),
dimension(nxvec,kx) :: biatx
1116 real(rprec),
dimension(nyvec,ky) :: biaty
1117 real(rprec),
dimension(max(nxvec,nyvec)) :: term
1118 real(rprec),
dimension(ky) :: work
1120 logical :: same,next
1125 call huntn(xknot,nx+kx,kx,xvec(1),leftx(1))
1128 leftx(ix) = leftx(ix-1)
1129 same = (xknot(leftx(ix)) .le. xvec(ix)) &
1130 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
1131 if(.not. same )
then
1132 leftx(ix) = leftx(ix) + 1
1133 next = (xknot(leftx(ix)) .le. xvec(ix)) &
1134 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
1136 &
call huntn(xknot,nx+kx,kx,xvec(ix),leftx(ix))
1141 if (xknot(i) .gt. xknot(i+1))
then
1142 write(6,*)
"subroutine dbs2gd:"
1143 write(6,*)
"xknot(i) <= xknot(i+1) required."
1144 write(6,*) i, xknot(i), xknot(i+1)
1152 if ((xvec(i).lt.xknot(1)).or.(xvec(i).gt.xknot(nx+kx)))
then
1153 write(6,*)
"subroutine dbs2gd:"
1154 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
1155 write(6,*)
"x = ", xvec(i)
1162 call huntn(yknot,ny+ky,ky,yvec(1),lefty(1))
1165 lefty(iy) = lefty(iy-1)
1166 same = (yknot(lefty(iy)) .le. yvec(iy)) &
1167 & .and. (yvec(iy) .le. yknot(lefty(iy)+1))
1168 if(.not. same )
then
1169 lefty(iy) = lefty(iy) + 1
1170 next = (yknot(lefty(iy)) .le. yvec(iy)) &
1171 & .and. (yvec(iy) .le. yknot(lefty(iy)+1))
1172 if (.not. next)
call huntn(yknot,ny+ky,ky,yvec(iy),lefty(iy))
1177 if (yknot(i) .gt. yknot(i+1))
then
1178 write(6,*)
"subroutine dbs2gd:"
1179 write(6,*)
"yknot(i) <= yknot(i+1) required."
1180 write(6,*) i, yknot(i), yknot(i+1)
1188 if ((yvec(i).lt.yknot(1)).or.(yvec(i).gt.yknot(ny+ky)))
then
1189 write(6,*)
"subroutine dbs2gd:"
1190 write(6,*)
"iy with yknot(iy) <= y < yknot(iy+1) required."
1191 write(6,*)
"y = ", yvec(i)
1196 if ((iderx .eq. 0) .and. (idery .eq. 0))
then
1204 dr(ix,ik) = xknot(leftx(ix)+ik) - xvec(ix)
1205 dl(ix,ik) = xvec(ix) - xknot(leftx(ix)+1-ik)
1211 term(ix) = biatx(ix,il) &
1212 & / (dr(ix,il) + dl(ix,ik+1-il))
1213 biatx(ix,il) = save1(ix) + dr(ix,il) * term(ix)
1214 save1(ix) = dl(ix,ik+1-il) * term(ix)
1219 biatx(ix,ik+1) = save1(ix)
1229 dr(iy,ik) = yknot(lefty(iy)+ik) - yvec(iy)
1230 dl(iy,ik) = yvec(iy) - yknot(lefty(iy)+1-ik)
1236 term(iy) = biaty(iy,il) &
1237 & / (dr(iy,il) + dl(iy,ik+1-il))
1238 biaty(iy,il) = save1(iy) + dr(iy,il) * term(iy)
1239 save1(iy) = dl(iy,ik+1-il) * term(iy)
1244 biaty(iy,ik+1) = save1(iy)
1258 val(ix,iy) = val(ix,iy) &
1259 & + biatx(ix,ikx) * biaty(iy,iky) &
1260 & * bcoef(leftx(ix)-kx+ikx,lefty(iy)-ky+iky)
1266 elseif (((iderx .ge. 1) .or. (idery .ge. 1)) &
1267 & .and. ( (iderx .lt. kx) .and. (idery .lt. ky)))
then
1272 work(iky) = dbsdca(iderx,xvec(ix),kx,xknot,nx, &
1273 & bcoef(1,lefty(iy)-ky+iky),leftx(ix))
1275 val(ix,iy) = dbsder(idery,yvec(iy),ky, &
1276 & yknot(lefty(iy)-ky+1),ky,work)
1290 end subroutine dbs2gd
1294 subroutine dbs3in(nx,xvec,ny,yvec,nz,zvec,xyzdata,ldf,mdf,kx,ky,kz, &
1295 & xknot,yknot,zknot,bcoef)
1344 integer,
intent(in) :: nx, ny, nz, kx, ky, kz
1345 integer,
intent(in) :: ldf, mdf
1347 real(rprec),
dimension(nx),
intent(in) :: xvec
1348 real(rprec),
dimension(ny),
intent(in) :: yvec
1349 real(rprec),
dimension(nz),
intent(in) :: zvec
1350 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
1351 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
1352 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
1353 real(rprec),
dimension(ldf,mdf,nz),
intent(in) :: xyzdata
1354 real(rprec),
dimension(nx,ny,nz),
intent(out) :: bcoef
1357 real(rprec),
allocatable :: work1(:,:,:)
1358 real(rprec),
dimension(nz) :: work2
1359 real(rprec),
dimension((2*kz-1)*nz) :: work3
1361 allocate (work1(nx,ny,nz), stat=iz)
1362 if (iz .ne. 0) stop
'allocation error in dbs3in'
1364 call spli3d(zvec,ldf,mdf,xyzdata,zknot,nz,kz,nx,ny,work2,work3,work1, &
1368 call dbs2in(nx,xvec,ny,yvec,work1(1,1,iz),nx,kx,ky,xknot,yknot, &
1374 end subroutine dbs3in
1378 subroutine spli3d(xyzvec,ldf,mdf,xyzdata,xyzknot,n,k,m,l,work2,work3, &
1383 integer,
intent(in) :: ldf, mdf, n, k, m, l
1384 integer,
intent(in) :: nx, ny, nz
1385 real(rprec),
dimension(n),
intent(in) :: xyzvec
1386 real(rprec),
dimension(n+k),
intent(in) :: xyzknot
1387 real(rprec),
dimension(ldf,mdf,*),
intent(in) :: xyzdata
1388 real(rprec),
dimension(nx,ny,nz),
intent(out) :: bcoef
1389 real(rprec),
dimension(n),
intent(out) :: work2
1390 real(rprec),
dimension((2*k-1)*n),
intent(out) :: work3
1392 integer :: np1, km1, kpkm2, left, lenq, i, ilp1mx, j, jj, iflag, in
1393 real(rprec) :: xyzveci
1400 lenq = n * (k + km1)
1408 ilp1mx = min0(i+k,np1)
1410 if (xyzveci .lt. xyzknot(left))
go to 998
1411 30
if (xyzveci .lt. xyzknot(left+1))
go to 40
1413 if (left .lt. ilp1mx)
go to 30
1415 if (xyzveci .gt. xyzknot(left+1))
go to 998
1416 40
call bsplvb(xyzknot,n+k,k,1,xyzveci,left,work2)
1417 jj = i - left + 1 + (left - k) * (k + km1)
1420 work3(jj) = work2(j)
1424 call banfac(work3,k+km1,n,km1,km1,iflag)
1426 if (iflag .ne. 1)
then
1427 write(6,*)
"subroutine dbs3in: error"
1428 write(6,*)
"no solution of linear equation system !!!"
1435 work2(in) = xyzdata(i,j,in)
1438 call banslv(work3,k+km1,n,km1,km1,work2)
1441 bcoef(i,j,in) = work2(in)
1449 998
write(6,*)
"subroutine db3in:"
1450 write(6,*)
"i with knot(i) <= x/y/z < knot(i+1) required."
1451 write(6,*)
"knot(1) = ", xyzknot(1)
1452 write(6,*)
"knot(n+k) = ", xyzknot(n+k)
1453 write(6,*)
" x/y/z = ", xyzveci
1457 end subroutine spli3d
1461 function dbs3vl(x,y,z,kx,ky,kz,xknot,yknot,zknot,nx,ny,nz,bcoef)
1500 integer,
intent(in) :: nx, ny, nz, kx, ky, kz
1501 real(rprec),
intent(in) :: x, y, z
1502 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
1503 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
1504 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
1505 real(rprec),
dimension(nx,ny,nz),
intent(in) :: bcoef
1506 real(rprec) :: dbs3vl
1508 integer :: iz, nintz
1509 real(rprec),
dimension(kz) :: work
1519 if (zknot(iz) .gt. zknot(iz + 1))
then
1520 write(6,*)
"subroutine dbs3vl:"
1521 write(6,*)
"zknot(iz) <= zknot(iz+1) required."
1522 write(6,*) iz, zknot(iz), zknot(iz+1)
1525 if((zknot(iz) .le. z) .and. (z .lt. zknot(iz + 1))) nintz = iz
1528 if(nintz .eq. 0)
then
1529 write(6,*)
"subroutine dbs3vl:"
1530 write(6,*)
"iz with zknot(iz) <= z < zknot(iz+1) required."
1531 write(6,*)
"zknot(iz) = ", zknot(iz)
1532 write(6,*)
" z = ", z
1533 write(6,*)
"zknot(iz+1) = ", zknot(iz+1)
1538 work(iz) = dbs2vl(x,y,kx,ky,xknot,yknot,nx,ny,bcoef(1,1,nintz-kz+iz))
1541 dbs3vl = dbsval(z,kz,zknot(nintz-kz+1),kz,work)
1547 function dbs3dr(iderx,idery,iderz,x,y,z,kx,ky,kz,xknot,yknot,zknot, &
1591 integer,
intent(in) :: iderx, idery, iderz
1592 integer,
intent(in) :: nx, ny, nz, kx, ky, kz
1593 real(rprec),
intent(in) :: x, y, z
1594 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
1595 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
1596 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
1597 real(rprec),
dimension(nx,ny,nz),
intent(in) :: bcoef
1598 real(rprec) :: dbs3dr
1600 integer :: iz, nintz
1601 real(rprec),
dimension(kz) :: work
1611 if (zknot(iz) .gt. zknot(iz + 1))
then
1612 write(6,*)
"subroutine dbs3vl:"
1613 write(6,*)
"zknot(iz) <= zknot(iz+1) required."
1614 write(6,*) iz, zknot(iz), zknot(iz+1)
1617 if((zknot(iz) .le. z) .and. (z .lt. zknot(iz + 1))) nintz = iz
1620 if(nintz .eq. 0)
then
1621 write(6,*)
"subroutine dbs3dr:"
1622 write(6,*)
"iz with zknot(iz) <= z < zknot(iz+1) required."
1623 write(6,*)
"zknot(iz) = ", zknot(iz)
1624 write(6,*)
" z = ", z
1625 write(6,*)
"zknot(iz+1) = ", zknot(iz+1)
1630 work(iz) = dbs2dr(iderx,idery,x,y,kx,ky,xknot,yknot,nx,ny, &
1631 & bcoef(1,1,nintz-kz+iz))
1634 dbs3dr = dbsder(iderz,z,kz,zknot(nintz-kz+1),kz,work)
1639 subroutine dbs3gd(iderx,idery,iderz,nxvec,xvec,nyvec,yvec,nzvec,zvec, &
1640 & kx,ky,kz,xknot,yknot,zknot,nx,ny,nz,bcoef,val,ldf,mdf)
1696 integer,
intent(in) :: iderx, idery, iderz
1697 integer,
intent(in) :: nxvec, nyvec, nzvec
1698 integer,
intent(in) :: kx, nx, ky, ny, kz, nz
1699 integer,
intent(in) :: ldf,mdf
1701 real(rprec),
dimension(nxvec),
intent(in) :: xvec
1702 real(rprec),
dimension(nyvec),
intent(in) :: yvec
1703 real(rprec),
dimension(nzvec),
intent(in) :: zvec
1704 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
1705 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
1706 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
1707 real(rprec),
dimension(nx,ny,nz),
intent(in) :: bcoef
1708 real(rprec),
dimension(ldf,mdf,*),
intent(out) :: val
1710 integer :: i, ik, il, ix, iy, iz
1711 integer :: ikx, iky, ikz
1712 integer,
dimension(nxvec) :: leftx
1713 integer,
dimension(nyvec) :: lefty
1714 integer,
dimension(nzvec) :: leftz
1715 real(rprec),
dimension(nxvec,kx) :: biatx
1716 real(rprec),
dimension(nyvec,ky) :: biaty
1717 real(rprec),
dimension(nzvec,kz) :: biatz
1718 real(rprec),
dimension(max(nxvec,nyvec,nzvec)) :: term, save1
1720 real(rprec),
dimension(max(nxvec,nyvec,nzvec), max(kx,ky,kz)) :: dl, dr
1722 logical :: same,next
1726 if (xknot(i) .gt. xknot(i+1))
then
1727 write(6,*)
"subroutine dbs3gd:"
1728 write(6,*)
"xknot(i) <= xknot(i+1) required."
1729 write(6,*) i, xknot(i), xknot(i+1)
1737 if ((xvec(i).lt.xknot(1)).or.(xvec(i).gt.xknot(nx+kx)))
then
1738 write(6,*)
"subroutine dbs3gd:"
1739 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
1740 write(6,*)
"x = ", xvec(i)
1742 write(6,*)
'i,xknot(1),xknot(nx+kx) ',i,xknot(1),xknot(nx+kx)
1751 call huntn(xknot,nx+kx,kx,xvec(1),leftx(1))
1754 leftx(ix) = leftx(ix-1)
1755 same = (xknot(leftx(ix)) .le. xvec(ix)) &
1756 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
1757 if(.not. same )
then
1758 leftx(ix) = leftx(ix) + 1
1759 next = (xknot(leftx(ix)) .le. xvec(ix)) &
1760 & .and. (xvec(ix) .le. xknot(leftx(ix)+1))
1761 if (.not. next)
call huntn(xknot,nx+kx,kx,xvec(ix),leftx(ix))
1766 if (yknot(i) .gt. yknot(i+1))
then
1767 write(6,*)
"subroutine dbs3gd:"
1768 write(6,*)
"yknot(i) <= yknot(i+1) required."
1769 write(6,*) i, yknot(i), yknot(i+1)
1777 if ((yvec(i).lt.yknot(1)).or.(yvec(i).gt.yknot(ny+ky)))
then
1778 write(6,*)
"subroutine dbs3gd:"
1779 write(6,*)
"iy with yknot(iy) <= y < yknot(iy+1) required."
1780 write(6,*)
"y = ", yvec(i)
1787 call huntn(yknot,ny+ky,ky,yvec(1),lefty(1))
1790 lefty(iy) = lefty(iy-1)
1791 same = (yknot(lefty(iy)) .le. yvec(iy)) &
1792 & .and. (yvec(iy) .le. yknot(lefty(iy)+1))
1793 if(.not. same )
then
1794 lefty(iy) = lefty(iy) + 1
1795 next = (yknot(lefty(iy)) .le. yvec(iy)) &
1796 & .and. (yvec(iy) .le. yknot(lefty(iy)+1))
1797 if (.not. next)
call huntn(yknot,ny+ky,ky,yvec(iy),lefty(iy))
1802 if (zknot(i) .gt. zknot(i+1))
then
1803 write(6,*)
"subroutine dbs3gd:"
1804 write(6,*)
"zknot(i) <= zknot(i+1) required."
1805 write(6,*) i, zknot(i), zknot(i+1)
1813 if ((zvec(i).lt.zknot(1)).or.(zvec(i).gt.zknot(nz+kz)))
then
1814 write(6,*)
"subroutine dbs3gd:"
1815 write(6,*)
"iz with zknot(iz) <= z < zknot(iz+1) required."
1816 write(6,*)
"z = ", zvec(i)
1823 call huntn(zknot,nz+kz,kz,zvec(1),leftz(1))
1826 leftz(iz) = leftz(iz-1)
1827 same = (zknot(leftz(iz)) .le. zvec(iz)) &
1828 & .and. (zvec(iz) .le. zknot(leftz(iz)+1))
1829 if(.not. same )
then
1830 leftz(iz) = leftz(iz) + 1
1831 next = (zknot(leftz(iz)) .le. zvec(iz)) &
1832 & .and. (zvec(iz) .le. zknot(leftz(iz)+1))
1833 if (.not. next)
call huntn(zknot,nz+kz,kz,zvec(iz),leftz(iz))
1837 if ((iderx .eq. 0) .and. (idery .eq. 0) .and. (iderz .eq.0))
then
1845 dr(ix,ik) = xknot(leftx(ix)+ik) - xvec(ix)
1846 dl(ix,ik) = xvec(ix) - xknot(leftx(ix)+1-ik)
1852 term(ix) = biatx(ix,il) / (dr(ix,il) + dl(ix,ik+1-il))
1853 biatx(ix,il) = save1(ix) + dr(ix,il) * term(ix)
1854 save1(ix) = dl(ix,ik+1-il) * term(ix)
1859 biatx(ix,ik+1) = save1(ix)
1869 dr(iy,ik) = yknot(lefty(iy)+ik) - yvec(iy)
1870 dl(iy,ik) = yvec(iy) - yknot(lefty(iy)+1-ik)
1876 term(iy) = biaty(iy,il) / (dr(iy,il) + dl(iy,ik+1-il))
1877 biaty(iy,il) = save1(iy) + dr(iy,il) * term(iy)
1878 save1(iy) = dl(iy,ik+1-il) * term(iy)
1883 biaty(iy,ik+1) = save1(iy)
1893 dr(iz,ik) = zknot(leftz(iz)+ik) - zvec(iz)
1894 dl(iz,ik) = zvec(iz) - zknot(leftz(iz)+1-ik)
1900 term(iz) = biatz(iz,il) / (dr(iz,il) + dl(iz,ik+1-il))
1901 biatz(iz,il) = save1(iz) + dr(iz,il) * term(iz)
1902 save1(iz) = dl(iz,ik+1-il) * term(iz)
1907 biatz(iz,ik+1) = save1(iz)
1914 val(ix,iy,iz) = zero
1925 val(ix,iy,iz) = val(ix,iy,iz) &
1926 & + biatx(ix,ikx) * biaty(iy,iky) &
1928 & * bcoef(leftx(ix)-kx+ikx, &
1929 & lefty(iy)-ky+iky,leftz(iz)-kz+ikz)
1943 val(ix,iy,iz) = dbs3dr0(iderx,idery,iderz,xvec(ix), &
1944 & yvec(iy),zvec(iz),kx,ky,kz,xknot,yknot, &
1945 & zknot,nx,ny,nz,bcoef, &
1946 & leftx(ix),lefty(iy),leftz(iz))
1953 end subroutine dbs3gd
1957 subroutine bsplvb(t,n,jhigh,index,x,left,biatx)
1961 integer,
intent(in) :: n, jhigh, index, left
1963 real(rprec),
intent(in) :: x
1964 real(rprec),
dimension(n),
intent(in) :: t
1965 real(rprec),
dimension(jhigh),
intent(out) :: biatx
1969 real(rprec) :: saved, term
1970 real(rprec),
dimension(jhigh) :: dl, dr
1973 if (index .eq. 1)
then
1976 if (j .ge. jhigh)
return
1981 dr(j) = t(left+j) - x
1982 dl(j) = x - t(left+1-j)
1986 term = biatx(i) / (dr(i) + dl(jp1-i))
1987 biatx(i) = saved + dr(i) * term
1988 saved = dl(jp1-i) * term
1994 if (j .lt. jhigh)
go to 20
1996 end subroutine bsplvb
2000 subroutine banfac(w,nroww,nrow,nbandl,nbandu,iflag)
2004 integer,
intent(in) :: nroww,nrow
2005 integer,
intent(in) :: nbandl,nbandu
2006 integer,
intent(out) :: iflag
2007 real(rprec),
dimension(nroww,nrow),
intent(inout) :: w
2009 real(rprec) :: pivot, factor
2010 integer :: middle, nrowm1, jmax, kmax, ipk, midmk, i, j, k
2017 if (nrowm1 .lt. 0)
goto 999
2018 if (nrowm1 .eq. 0)
goto 900
2019 if (nrowm1 .gt. 0)
goto 10
2021 10
if (nbandl .gt. 0)
go to 30
2024 if (w(middle,i) .eq. zero)
go to 999
2029 30
if (nbandu .gt. 0)
go to 60
2033 if(pivot .eq. zero)
go to 999
2034 jmax = min0(nbandl, nrow - i)
2036 w(middle+j,i) = w(middle+j,i) / pivot
2044 if (pivot .eq. zero)
go to 999
2045 jmax = min0(nbandl,nrow - i)
2047 w(middle+j,i) = w(middle+j,i) / pivot
2050 kmax = min0(nbandu,nrow - i)
2055 factor = w(midmk,ipk)
2057 w(midmk+j,ipk) = w(midmk+j,ipk) - w(middle+j,i) &
2063 900
if (w(middle,nrow) .ne. zero)
return
2066 end subroutine banfac
2069 subroutine banslv(w,nroww,nrow,nbandl,nbandu,b)
2073 integer,
intent(in) :: nroww,nrow
2074 integer,
intent(in) :: nbandl,nbandu
2075 real(rprec),
dimension(nroww,nrow),
intent(in) :: w
2076 real(rprec),
dimension(nrow),
intent(inout) :: b
2078 integer :: middle, nrowm1, jmax, i, j
2081 if (nrow .eq. 1)
goto 99
2083 if (nbandl .eq. 0)
goto 30
2086 jmax = min0(nbandl, nrow - i)
2088 b(i+j) = b(i+j) - b(i) * w(middle+j,i)
2092 30
if (nbandu .gt. 0)
goto 50
2095 b(i) = b(i) / w(1,i)
2100 50
do i = nrow, 2, -1
2101 b(i) = b(i)/w(middle,i)
2102 jmax = min0(nbandu,i-1)
2104 b(i-j) = b(i-j) - b(i) * w(middle-j,i)
2108 99 b(1) = b(1) / w(middle,1)
2110 end subroutine banslv
2113 subroutine huntn(xx,n,kord,x,jlo)
2117 integer,
intent(in) :: n, kord
2118 real(rprec),
intent(in) :: x
2119 real(rprec),
dimension(n),
intent(in) :: xx
2121 integer,
intent(inout) :: jlo
2123 integer :: max, null, jhi, jm, inc
2132 if (jlo.le.null.or.jlo.gt.max)
then
2140 if (x .ge. xx(jlo))
then
2142 if (jhi .gt. max)
then
2144 else if (x .ge. xx(jhi))
then
2152 if (jlo .le. null)
then
2154 else if (x .lt. xx(jlo))
then
2161 30
if (jhi-jlo.eq.1)
return
2163 jm = (jhi + jlo) / 2
2164 if (x .gt. xx(jm))
then
2172 end subroutine huntn
2175 function dbs2dr0(iderx,idery,x,y,kx,ky,xknot,yknot,nx,ny,bcoef,nintx,ninty)
2216 integer,
intent(in) :: iderx, idery
2217 integer,
intent(in) :: kx, nx, ky, ny
2218 real(rprec) :: dbs2dr0
2219 real(rprec),
intent(in) :: x, y
2220 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
2221 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
2222 real(rprec),
dimension(nx,ny),
intent(in) :: bcoef
2224 integer,
intent(in) :: nintx,ninty
2226 integer :: ix, iy, iky
2227 real(rprec),
dimension(ky) :: work
2273 work(iky) = dbsdca(iderx,x,kx,xknot,nx,bcoef(1,ninty-ky+iky),nintx)
2276 dbs2dr0 = dbsder0(idery,y,ky,yknot(ninty-ky+1),ky,work)
2278 end function dbs2dr0
2281 function dbs3dr0(iderx,idery,iderz,x,y,z,kx,ky,kz,xknot,yknot,zknot, &
2282 & nx,ny,nz,bcoef, nintx,ninty,nintz)
2325 integer,
intent(in) :: iderx, idery, iderz
2326 integer,
intent(in) :: nx, ny, nz, kx, ky, kz
2327 real(rprec),
intent(in) :: x, y, z
2328 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
2329 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
2330 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
2331 real(rprec),
dimension(nx,ny,nz),
intent(in) :: bcoef
2332 real(rprec) :: dbs3dr0
2337 integer,
intent(in) :: nintx,ninty,nintz
2340 real(rprec),
dimension(kz) :: work
2342 logical,
parameter :: need_check = .false.
2401 work(iz) = dbs2dr0(iderx,idery,x,y,kx,ky,xknot,yknot,nx,ny, &
2402 & bcoef(1,1,nintz-kz+iz), nintx,ninty)
2405 dbs3dr0 = dbsder0(iderz,z,kz,zknot(nintz-kz+1),kz,work)
2407 end function dbs3dr0
2411 function dbsder0(iderx,x,kx,xknot,nx,bcoef )
2435 integer,
intent(in) :: iderx, kx, nx
2436 real(rprec) :: dbsder0
2437 real(rprec),
intent(in) :: x
2438 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
2439 real(rprec),
dimension(nx),
intent(in) :: bcoef
2447 integer :: ix, ik, il, leftx
2448 real(rprec) ::
save, save1, save2, y, sum, dik
2449 real(rprec),
dimension(kx) :: work, dl, dr,bsp
2481 select case(nxpkxm1)
2484 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2491 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2498 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2505 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2512 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2519 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2526 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2533 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2540 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2547 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2554 if ((xknot(ix).le.x).and.(x.le.xknot(ix+1)) )
then
2562 dbsder0 = dbsdca(iderx,x,kx,xknot,nx,bcoef,leftx)
2565 end function dbsder0
2568 subroutine dbs3vd(iderx,idery,iderz,nxyz,xvec,yvec,zvec, &
2569 & kx,ky,kz,xknot,yknot,zknot,nx,ny,nz,bcoef,val, &
2570 & is_uniformx, is_uniformy, is_uniformz)
2618 integer,
intent(in) :: iderx
2619 integer,
intent(in) :: idery
2620 integer,
intent(in) :: iderz
2621 integer,
intent(in) :: nxyz
2622 integer,
intent(in) :: kx, nx
2623 integer,
intent(in) :: ky, ny
2624 integer,
intent(in) :: kz, nz
2626 real(rprec),
dimension(nxyz),
intent(in) :: xvec
2627 real(rprec),
dimension(nxyz),
intent(in) :: yvec
2628 real(rprec),
dimension(nxyz),
intent(in) :: zvec
2629 real(rprec),
dimension(nx+kx),
intent(in) :: xknot
2630 real(rprec),
dimension(ny+ky),
intent(in) :: yknot
2631 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
2632 real(rprec),
dimension(nx,ny,nz),
intent(in) :: bcoef
2633 real(rprec),
dimension(nxyz),
intent(inout) :: val
2635 logical,
intent(in) :: is_uniformx
2636 logical,
intent(in) :: is_uniformy
2637 logical,
intent(in) :: is_uniformz
2639 integer :: i, ik, il
2640 integer :: ix, iy, iz
2641 integer :: ikx, iky, ikz
2642 integer,
dimension(nxyz) :: leftx
2643 integer,
dimension(nxyz) :: lefty
2644 integer,
dimension(nxyz) :: leftz
2645 real(rprec),
dimension(nxyz,kx) :: biatx
2646 real(rprec),
dimension(nxyz,ky) :: biaty
2647 real(rprec),
dimension(nxyz,kz) :: biatz
2648 real(rprec),
dimension(nxyz) :: term, save1
2650 real(rprec),
dimension(nxyz, max(kx,ky,kz)) :: dl, dr
2653 logical :: use_huntn = .false.
2654 logical :: use_linear = .false.
2655 logical :: use_vsearch = .false.
2656 logical :: use_hash = .true.
2657 logical :: isok, is_uniform
2658 integer :: ileft, ijk, istart,iend
2659 integer :: t1,t2,count_rate
2660 real(rprec) :: delta
2661 real(rprec),
parameter :: tol=1.0d-7
2663 integer :: nintx,ninty,nintz
2664 real(rprec),
dimension(kz) :: workz
2665 real(rprec),
dimension(ky) :: worky
2667 real(rprec),
parameter :: zero = 0
2668 real(rprec),
parameter :: one = 1
2670 logical,
parameter :: use_Axyz = .false.
2671 real(rprec),
dimension(kx,ky,kz) :: Axyz
2672 real(rprec),
dimension(ky,kz) :: Ayz
2673 real(rprec),
dimension(kz) :: Az
2678 call system_clock(t1,count_rate)
2679 isok = all(xknot(2:(nx+kx)) .ge. xknot(1:(nx+kx-1)))
2682 if (xknot(i) .gt. xknot(i+1))
then
2683 write(6,*)
"subroutine dbs3vd:"
2684 write(6,*)
"xknot(i) <= xknot(i+1) required."
2685 write(6,*) i, xknot(i), xknot(i+1)
2694 isok = all(yknot(2:(ny+ky)) .ge. yknot(1:(ny+ky-1)))
2697 if (yknot(i) .gt. yknot(i+1))
then
2698 write(6,*)
"subroutine dbs3vd:"
2699 write(6,*)
"yknot(i) <= yknot(i+1) required."
2700 write(6,*) i, yknot(i), yknot(i+1)
2709 isok = all(zknot(2:(nz+kz)) .ge. zknot(1:(nz+kz-1)))
2712 if (zknot(i) .gt. zknot(i+1))
then
2713 write(6,*)
"subroutine dbs3vd:"
2714 write(6,*)
"zknot(i) <= zknot(i+1) required."
2715 write(6,*) i, zknot(i), zknot(i+1)
2723 call system_clock(t2,count_rate)
2724 if (idebug.ge.2)
then
2725 write(*,*)
'time for 1st check ',real(t2-t1)/real(count_rate)
2732 call system_clock(t1,count_rate)
2737 call huntn(xknot,nx+kx,kx,xvec(i),ileft)
2742 call huntn(yknot,ny+ky,ky,yvec(i),ileft)
2747 call huntn(zknot,nz+kz,kz,zvec(i),ileft)
2750 else if (use_linear)
then
2757 if ((xknot(ix).le.xvec(ijk)).and.(xvec(ijk).le.xknot(ix+1)))
then
2764 if ((yknot(iy).le.yvec(ijk)).and.(yvec(ijk).le.yknot(iy+1)))
then
2771 if ((zknot(iz).le.zvec(ijk)).and.(zvec(ijk).le.zknot(iz+1)))
then
2777 else if (use_vsearch)
then
2778 if (idebug.ge.2)
then
2779 write(*,*)
'using vsearch '
2782 call vsearch(nx+kx,xknot, nxyz, xvec, leftx )
2783 call vsearch(ny+ky,yknot, nxyz, yvec, lefty )
2784 call vsearch(nz+kz,zknot, nxyz, zvec, leftz )
2785 else if (use_hash)
then
2793 delta = xknot(istart+1)-xknot(istart)
2794 is_uniform = is_uniformx
2796 if (is_uniform)
then
2797 call vhash(xknot,nx,kx,nxyz,xvec,leftx)
2799 call vsearch(nx+kx,xknot, nxyz,xvec,leftx)
2806 delta = yknot(istart+1)-yknot(istart)
2807 is_uniform = is_uniformy
2809 if (is_uniform)
then
2810 call vhash(yknot,ny,ky,nxyz,yvec,lefty)
2812 call vsearch(ny+ky,yknot, nxyz,yvec,lefty)
2818 delta = zknot(istart+1)-zknot(istart)
2819 is_uniform = is_uniformz
2821 if (is_uniform)
then
2822 call vhash(zknot,nz,kz,nxyz,zvec,leftz)
2824 call vsearch(nz+kz,zknot, nxyz,zvec,leftz)
2831 call system_clock(t2,count_rate)
2832 if (idebug.ge.2)
then
2833 write(*,*)
'time for index search ',real(t2-t1)/real(count_rate)
2841 call system_clock(t1,count_rate)
2845 if (all((1.le.leftx(1:nxyz)).and.(leftx(1:nxyz).lt.nx+kx)))
then
2847 isok = all((xknot( leftx(1:nxyz) ) .le. xvec(1:nxyz)).and. &
2848 & (xvec(1:nxyz).le.xknot( 1+leftx(1:nxyz))) )
2853 isok = (1.le.ileft).and.(ileft.lt.nx+kx)
2855 isok= (xknot( ileft ).le. xvec(i)).and. &
2856 & (xvec(i).le.xknot(ileft+1))
2860 write(6,*)
"subroutine dbs3vd:"
2861 write(6,*)
"ix with xknot(ix) <= x < xknot(ix+1) required."
2862 write(6,*)
"x = ", xvec(i)
2863 write(6,*)
"i,ileft ",i,ileft
2864 write(6,*)
'nx,kx ',nx,kx
2866 write(*,*)
'ix,xknot(ix) ',ix,xknot(ix)
2868 stop
'** error in dbs3vd ** '
2874 if (all((1.le.lefty(1:nxyz)).and.(lefty(1:nxyz).lt.ny+ky)))
then
2876 isok = all((yknot( lefty(1:nxyz) ) .le. yvec(1:nxyz)).and. &
2877 & (yvec(1:nxyz).le.yknot( 1+lefty(1:nxyz))) )
2882 isok = (1.le.ileft).and.(ileft.lt.ny+ky)
2884 isok=(yknot( ileft ).le. yvec(i)).and. &
2885 & (yvec(i).le.yknot(ileft+1))
2889 write(6,*)
"subroutine dbs3vd:"
2890 write(6,*)
"iy with yknot(iy) <= y < yknot(iy+1) required."
2891 write(6,*)
"y = ", yvec(i)
2892 write(6,*)
"i,ileft ",i,ileft
2893 write(6,*)
'ny,ky ',ny,ky
2895 write(*,*)
'iy,yknot(iy) ',iy,yknot(iy)
2897 stop
'** error in dbs3vd ** '
2903 if (all((1.le.leftz(1:nxyz)).and.(leftz(1:nxyz).lt.nz+kz)))
then
2905 isok = all((zknot( leftz(1:nxyz) ) .le. zvec(1:nxyz)).and. &
2906 & (zvec(1:nxyz).le.zknot( 1+leftz(1:nxyz))) )
2911 isok = (1.le.ileft).and.(ileft.lt.nz+kz)
2913 isok= (zknot( ileft ).le. zvec(i)).and. &
2914 & (zvec(i).le.zknot(ileft+1))
2918 write(6,*)
"subroutine dbs3vd:"
2919 write(6,*)
"iz with zknot(iz) <= z < zknot(iz+1) required."
2920 write(6,*)
"z = ", zvec(i)
2921 write(6,*)
"i,ileft ",i,ileft
2922 write(6,*)
'nz,kz ',nz,kz
2924 write(*,*)
'iz,zknot(iz) ',iz,zknot(iz)
2926 stop
'** error in dbs3vd ** '
2931 call system_clock(t2,count_rate)
2932 if (idebug.ge.2)
then
2933 write(*,*)
'time for 2nd check ',real(t2-t1)/real(count_rate)
2937 if ((iderx .eq. 0) .and. (idery .eq. 0) .and. (iderz .eq.0))
then
2947 dr(ix,ik) = xknot(nintx+ik) - xvec(ix)
2948 dl(ix,ik) = xvec(ix) - xknot(nintx+1-ik)
2962 term(ix) = biatx(ix,il) / (dr(ix,il) + dl(ix,ik+1-il))
2965 biatx(ix,il) = save1(ix) + dr(ix,il) * term(ix)
2968 save1(ix) = dl(ix,ik+1-il) * term(ix)
2973 biatx(ix,ik+1) = save1(ix)
2986 dr(iy,ik) = yknot(ninty+ik) - yvec(iy)
2987 dl(iy,ik) = yvec(iy) - yknot(ninty+1-ik)
3000 term(iy) = biaty(iy,il) / (dr(iy,il) + dl(iy,ik+1-il))
3003 biaty(iy,il) = save1(iy) + dr(iy,il) * term(iy)
3006 save1(iy) = dl(iy,ik+1-il) * term(iy)
3011 biaty(iy,ik+1) = save1(iy)
3023 dr(iz,ik) = zknot(nintz+ik) - zvec(iz)
3024 dl(iz,ik) = zvec(iz) - zknot(nintz+1-ik)
3036 term(iz) = biatz(iz,il) / (dr(iz,il) + dl(iz,ik+1-il))
3039 biatz(iz,il) = save1(iz) + dr(iz,il) * term(iz)
3042 save1(iz) = dl(iz,ik+1-il) * term(iz)
3047 biatz(iz,ik+1) = save1(iz)
3073 call system_clock(t1,count_rate)
3093 axyz(ikx,iky,ikz) = &
3094 & bcoef(nintx-kx+ikx,ninty-ky+iky,nintz-kz+ikz)
3115 ayz(iky,ikz) = ayz(iky,ikz) + &
3116 & axyz(ikx,iky,ikz)*biatx(ix,ikx)
3130 az(ikz) = az(ikz) + ayz(iky,ikz) * biaty(iy,iky)
3136 val(ijk) = val(ijk) + az(ikz)*biatz(iz,ikz)
3155 val(ijk) = val(ijk) + &
3156 & bcoef(nintx-kx+ikx,ninty-ky+iky,nintz-kz+ikz)*biatx(ix,ikx)* &
3157 & biaty(iy,iky)*biatz(iz,ikz)
3168 call system_clock(t2,count_rate)
3169 if (idebug.ge.2)
then
3170 write(*,*)
'time in val loop ',real(t2-t1)/real(count_rate)
3183 val(ijk) = dbs3dr0(iderx,idery,iderz,xvec(ix), &
3184 & yvec(iy),zvec(iz),kx,ky,kz,xknot,yknot, &
3185 & zknot,nx,ny,nz,bcoef, &
3186 & leftx(ix),lefty(iy),leftz(iz))
3192 end subroutine dbs3vd
3196 subroutine vsearch( n, x, m, vxc, vipos )
3198 integer,
intent(in) :: n
3199 real(rprec),
intent(in),
dimension(n) :: x
3200 integer,
intent(in) :: m
3201 real(rprec),
intent(in),
dimension(m) :: vxc
3202 integer,
intent(inout),
dimension(m) :: vipos
3207 integer :: ipos,i,j, ilo,ihi,imid, nit
3208 integer,
dimension(1) :: ipos1
3211 integer,
parameter :: k64=64*1024
3212 integer,
parameter :: k128=128*1024
3213 integer,
parameter :: k256=256*1024
3214 integer,
parameter :: k512=512*1024
3215 integer,
parameter :: m1=1024*1024
3216 integer,
parameter :: m2=2*m1
3217 integer,
parameter :: m4=4*m1
3218 integer,
parameter :: m8=8*m1
3219 integer,
parameter :: m16=16*m1
3220 integer,
parameter :: m32=32*m1
3221 integer,
parameter :: m64=64*m1
3225 data itable /2,4,8,16,32, &
3226 & 64,128,256,512,1024, &
3227 & 2048, 4096, 8192,16382, 32768, &
3228 & k64,k128,k512,m1,m2, &
3229 & m4,m8,m16,m32,m64/
3231 ipos1 = minloc( itable - n, itable .ge. n )
3239 if ((xc .le. x(1)).or.(xc.ge.x(n)))
then
3247 imid = (ihi + ilo)/2
3248 if ((x(imid).le.xc).and.(xc.le.x(imid+1)))
then
3251 else if (xc.le.x(imid))
then
3253 else if (xc.ge.x(imid))
then
3262 end subroutine vsearch
3265 subroutine vhash(zknot,nz,kz,nxyz,zvec,leftz)
3267 integer,
intent(in) :: nz,kz,nxyz
3268 real(rprec),
dimension(nz+kz),
intent(in) :: zknot
3269 real(rprec),
dimension(nxyz),
intent(in) :: zvec
3270 integer,
dimension(nxyz),
intent(inout) :: leftz
3272 integer :: ijk,istart,iend,i,im1,ip1,ileft
3277 dz = zknot(istart+1)-zknot(istart)
3289 ileft = int((z-zknot(istart))/dz) + istart
3290 leftz(ijk) = max(istart,min(iend-1,ileft) )
3296 if (z.lt.zknot(i))
then
3297 if ((zknot(istart-1).le.z).and.(z.le.zknot(istart)))
then
3298 leftz(ijk) = istart-1
3300 im1 = max(istart,min(iend-1,i-1))
3301 if ((zknot(im1).le.z).and.(z.le.zknot(im1+1)))
then
3305 else if (z.gt.zknot(i+1))
then
3306 if ((zknot(iend).le.z).and.(z.le.zknot(iend+1)))
then
3309 ip1 = max(istart,min(iend-1,i+1))
3310 if ((zknot(ip1).le.z).and.(z.le.zknot(ip1+1)))
then
3317 end subroutine vhash