forked from ECP-Astro/chimera2castro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbspline_sub_module.f90
2962 lines (2607 loc) · 145 KB
/
bspline_sub_module.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!*****************************************************************************************
!> author: Jacob Williams
! license: BSD
!
!# Description
!
! Multidimensional (1D-6D) B-spline interpolation of data on a regular grid.
! Basic pure subroutine interface.
!
!# Notes
!
! This module is based on the B-spline and spline routines from [1].
! The original Fortran 77 routines were converted to free-form source.
! Some of them are relatively unchanged from the originals, but some have
! been extensively refactored. In addition, new routines for
! 1d, 4d, 5d, and 6d interpolation were also created (these are simply
! extensions of the same algorithm into higher dimensions).
!
!# See also
! * An object-oriented interface can be found in [[bspline_oo_module]].
!
!# References
!
! 1. DBSPLIN and DTENSBS from the
! [NIST Core Math Library](http://www.nist.gov/itl/math/mcsd-software.cfm).
! Original code is public domain.
! 2. Carl de Boor, "A Practical Guide to Splines",
! Springer-Verlag, New York, 1978.
! 3. Carl de Boor, [Efficient Computer Manipulation of Tensor
! Products](http://dl.acm.org/citation.cfm?id=355831),
! ACM Transactions on Mathematical Software,
! Vol. 5 (1979), p. 173-182.
! 4. D.E. Amos, "Computation with Splines and B-Splines",
! SAND78-1968, Sandia Laboratories, March, 1979.
! 5. Carl de Boor,
! [Package for calculating with B-splines](http://epubs.siam.org/doi/abs/10.1137/0714026),
! SIAM Journal on Numerical Analysis 14, 3 (June 1977), p. 441-472.
module bspline_sub_module
use,intrinsic :: iso_fortran_env, only: real64
use,intrinsic :: iso_fortran_env, only: error_unit
implicit none
private
integer,parameter :: wp = real64 !! Real precision
!Spline function order (order = polynomial degree + 1)
integer,parameter,public :: bspline_order_quadratic = 3
integer,parameter,public :: bspline_order_cubic = 4
integer,parameter,public :: bspline_order_quartic = 5
integer,parameter,public :: bspline_order_quintic = 6
!main routines:
public :: db1ink, db1val
public :: db2ink, db2val
public :: db3ink, db3val
public :: db4ink, db4val
public :: db5ink, db5val
public :: db6ink, db6val
public :: get_status_message
contains
!*****************************************************************************************
!*****************************************************************************************
!> Determines the parameters of a function that interpolates
! the one-dimensional gridded data
! $$ [x(i),\mathrm{fcn}(i)] ~\mathrm{for}~ i=1,..,n_x $$
! The interpolating function and its derivatives may
! subsequently be evaluated by the function [[db1val]].
!
!# History
!
! * Jacob Williams, 10/30/2015 : Created 1D routine.
pure subroutine db1ink(x,nx,fcn,kx,iknot,tx,bcoef,iflag)
implicit none
integer,intent(in) :: nx !! Number of x abcissae
integer,intent(in) :: kx !! The order of spline pieces in x (>= 2, < nx). (order = polynomial degree + 1)
real(wp),dimension(:),intent(in) :: x !! `nx` array of x abcissae. Must be strictly increasing.
real(wp),dimension(:),intent(in) :: fcn !! `(nx)` array of function values to interpolate. `fcn(i)` should
!! contain the function value at the point `x(i)`
integer,intent(in) :: iknot !! 0 = knot sequence chosen by [[db1ink]].
!! 1 = knot sequence chosen by user.
real(wp),dimension(:),intent(inout) :: tx !! The `nx+kx` knots in the `x` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db1ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(out) :: bcoef !! `(nx)` array of coefficients of the b-spline interpolant.
integer,intent(out) :: iflag !! 0 = successful execution.
!! 2 = iknot out of range.
!! 3 = nx out of range.
!! 4 = kx out of range.
!! 5 = x not strictly increasing.
!! 6 = tx not non-decreasing.
!! 700 = size(x) /= size(fcn,1).
!! 706 = size(x) /= nx.
!! 712 = size(tx) /= nx+kx.
!! 800 = size(x) /= size(bcoef,1).
real(wp),dimension(2*kx*(nx+1)) :: work
logical :: status_ok
!check validity of inputs
call check_inputs('db1ink',&
iknot,&
iflag,&
nx=nx,&
kx=kx,&
x=x,&
f1=fcn,&
bcoef1=bcoef,&
tx=tx,&
status_ok=status_ok)
if (status_ok) then
!choose knots
if (iknot == 0) then
call dbknot(x,nx,kx,tx)
end if
!construct b-spline coefficients
call dbtpcf(x,nx,fcn,nx,1,tx,kx,bcoef,work,iflag)
end if
end subroutine db1ink
!*****************************************************************************************
!*****************************************************************************************
!> Evaluates the tensor product piecewise polynomial
! interpolant constructed by the routine [[db1ink]] or one of its
! derivatives at the point xval.
!
! To evaluate the interpolant itself, set idx=0,
! to evaluate the first partial with respect to x, set idx=1, and so on.
!
! db1val returns 0.0 if (xval,yval) is out of range. that is, if
!```fortran
! xval < tx(1) .or. xval > tx(nx+kx)
!```
! if the knots tx were chosen by [[db1ink]], then this is equivalent to:
!```fortran
! xval < x(1) .or. xval > x(nx)+epsx
!```
! where
!```fortran
! epsx = 0.1*(x(nx)-x(nx-1))
!```
!
! The input quantities tx, nx, kx, and bcoef should be
! unchanged since the last call of [[db1ink]].
!
!# History
!
! * Jacob Williams, 10/30/2015 : Created 1D routine.
pure subroutine db1val(xval,idx,tx,nx,kx,bcoef,f,iflag,inbvx)
implicit none
integer,intent(in) :: idx !! x derivative of piecewise polynomial to evaluate.
integer,intent(in) :: nx !! the number of interpolation points in x. (same as in last call to [[db1ink]])
integer,intent(in) :: kx !! order of polynomial pieces in x. (same as in last call to [[db1ink]])
real(wp),intent(in) :: xval !! x coordinate of evaluation point.
real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial in the x direction. (same as in last call to [[db1ink]])
real(wp),dimension(nx),intent(in) :: bcoef !! the b-spline coefficients computed by [[db1ink]].
real(wp),intent(out) :: f !! interpolated value
integer,intent(out) :: iflag !! status flag: 0 : no errors, /=0 : error
integer,intent(inout) :: inbvx !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
real(wp),dimension(3*kx) :: work
f = 0.0_wp
if (xval<tx(1) .or. xval>tx(nx+kx)) then
!write(error_unit,'(A)') 'db1val - x value out of bounds'
iflag = 601
return
end if
call dbvalu(tx,bcoef,nx,kx,idx,xval,inbvx,work,iflag,f)
end subroutine db1val
!*****************************************************************************************
!*****************************************************************************************
!> Determines the parameters of a function that interpolates
! the two-dimensional gridded data
! $$ [x(i),y(j),\mathrm{fcn}(i,j)] ~\mathrm{for}~ i=1,..,n_x ~\mathrm{and}~ j=1,..,n_y $$
! The interpolating function and its derivatives may
! subsequently be evaluated by the function [[db2val]].
!
! The interpolating function is a piecewise polynomial function
! represented as a tensor product of one-dimensional b-splines. the
! form of this function is
!
! $$ s(x,y) = \sum_{i=1}^{n_x} \sum_{j=1}^{n_y} a_{ij} u_i(x) v_j(y) $$
!
! where the functions \(u_i\) and \(v_j\) are one-dimensional b-spline
! basis functions. the coefficients \( a_{ij} \) are chosen so that
!
! $$ s(x(i),y(j)) = \mathrm{fcn}(i,j) ~\mathrm{for}~ i=1,..,n_x ~\mathrm{and}~ j=1,..,n_y $$
!
! Note that for each fixed value of y, \( s(x,y) \) is a piecewise
! polynomial function of x alone, and for each fixed value of x, \( s(x,y) \)
! is a piecewise polynomial function of y alone. in one dimension
! a piecewise polynomial may be created by partitioning a given
! interval into subintervals and defining a distinct polynomial piece
! on each one. the points where adjacent subintervals meet are called
! knots. each of the functions \(u_i\) and \(v_j\) above is a piecewise
! polynomial.
!
! Users of db2ink choose the order (degree+1) of the polynomial
! pieces used to define the piecewise polynomial in each of the x and
! y directions (kx and ky). users also may define their own knot
! sequence in x and y separately (tx and ty). if iflag=0, however,
! db2ink will choose sequences of knots that result in a piecewise
! polynomial interpolant with kx-2 continuous partial derivatives in
! x and ky-2 continuous partial derivatives in y. (kx knots are taken
! near each endpoint in the x direction, not-a-knot end conditions
! are used, and the remaining knots are placed at data points if kx
! is even or at midpoints between data points if kx is odd. the y
! direction is treated similarly.)
!
! After a call to db2ink, all information necessary to define the
! interpolating function are contained in the parameters nx, ny, kx,
! ky, tx, ty, and bcoef. These quantities should not be altered until
! after the last call of the evaluation routine [[db2val]].
!
!# History
!
! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.
! * JEC : 000330 modified array declarations.
! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.
pure subroutine db2ink(x,nx,y,ny,fcn,kx,ky,iknot,tx,ty,bcoef,iflag)
implicit none
integer,intent(in) :: nx !! Number of x abcissae
integer,intent(in) :: ny !! Number of y abcissae
integer,intent(in) :: kx !! The order of spline pieces in x (>= 2, < nx). (order = polynomial degree + 1)
integer,intent(in) :: ky !! The order of spline pieces in y (>= 2, < ny). (order = polynomial degree + 1)
real(wp),dimension(:),intent(in) :: x !! `nx` array of x abcissae. Must be strictly increasing.
real(wp),dimension(:),intent(in) :: y !! `ny` array of y abcissae. Must be strictly increasing.
real(wp),dimension(:,:),intent(in) :: fcn !! `(nx,ny)` matrix of function values to interpolate. `fcn(i,j)` should
!! contain the function value at the point `(x(i),y(j))`
integer,intent(in) :: iknot !! 0 = knot sequence chosen by [[db1ink]].
!! 1 = knot sequence chosen by user.
real(wp),dimension(:),intent(inout) :: tx !! The `nx+kx` knots in the `x` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db2ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: ty !! The `ny+ky` knots in the `y` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db2ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:,:),intent(out) :: bcoef !! `(nx,ny)` matrix of coefficients of the b-spline interpolant.
integer,intent(out) :: iflag !! 0 = successful execution.
!! 2 = iknot out of range.
!! 3 = nx out of range.
!! 4 = kx out of range.
!! 5 = x not strictly increasing.
!! 6 = tx not non-decreasing.
!! 7 = ny out of range.
!! 8 = ky out of range.
!! 9 = y not strictly increasing.
!! 10 = ty not non-decreasing.
!! 700 = size(x) /= size(fcn,1).
!! 701 = size(y) /= size(fcn,2).
!! 706 = size(x) /= nx.
!! 707 = size(y) /= ny.
!! 712 = size(tx) /= nx+kx.
!! 713 = size(ty) /= ny+ky.
!! 800 = size(x) /= size(bcoef,1).
!! 801 = size(y) /= size(bcoef,2).
real(wp),dimension(nx*ny) :: temp
real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1))) :: work
logical :: status_ok
!check validity of inputs
call check_inputs('db2ink',&
iknot,&
iflag,&
nx=nx,ny=ny,&
kx=kx,ky=ky,&
x=x,y=y,&
tx=tx,ty=ty,&
f2=fcn,&
bcoef2=bcoef,&
status_ok=status_ok)
if (status_ok) then
!choose knots
if (iknot == 0) then
call dbknot(x,nx,kx,tx)
call dbknot(y,ny,ky,ty)
end if
!construct b-spline coefficients
call dbtpcf(x,nx,fcn, nx,ny,tx,kx,temp, work,iflag)
if (iflag==0) call dbtpcf(y,ny,temp,ny,nx,ty,ky,bcoef,work,iflag)
end if
end subroutine db2ink
!*****************************************************************************************
!*****************************************************************************************
!> Evaluates the tensor product piecewise polynomial
! interpolant constructed by the routine [[db2ink]] or one of its
! derivatives at the point (xval,yval).
!
! To evaluate the interpolant
! itself, set idx=idy=0, to evaluate the first partial with respect
! to x, set idx=1,idy=0, and so on.
!
! db2val returns 0.0 if (xval,yval) is out of range. that is, if
!```fortran
! xval < tx(1) .or. xval > tx(nx+kx) .or.
! yval < ty(1) .or. yval > ty(ny+ky)
!```
! if the knots tx and ty were chosen by [[db2ink]], then this is equivalent to:
!```fortran
! xval < x(1) .or. xval > x(nx)+epsx .or.
! yval < y(1) .or. yval > y(ny)+epsy
!```
! where
!```fortran
! epsx = 0.1*(x(nx)-x(nx-1))
! epsy = 0.1*(y(ny)-y(ny-1))
!```
!
! The input quantities tx, ty, nx, ny, kx, ky, and bcoef should be
! unchanged since the last call of [[db2ink]].
!
!# History
!
! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.
! * JEC : 000330 modified array declarations.
! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.
pure subroutine db2val(xval,yval,idx,idy,tx,ty,nx,ny,kx,ky,bcoef,f,iflag,inbvx,inbvy,iloy)
implicit none
integer,intent(in) :: idx !! x derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idy !! y derivative of piecewise polynomial to evaluate.
integer,intent(in) :: nx !! the number of interpolation points in x. (same as in last call to [[db2ink]])
integer,intent(in) :: ny !! the number of interpolation points in y. (same as in last call to [[db2ink]])
integer,intent(in) :: kx !! order of polynomial pieces in x. (same as in last call to [[db2ink]])
integer,intent(in) :: ky !! order of polynomial pieces in y. (same as in last call to [[db2ink]])
real(wp),intent(in) :: xval !! x coordinate of evaluation point.
real(wp),intent(in) :: yval !! y coordinate of evaluation point.
real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial in the x direction. (same as in last call to [[db2ink]])
real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial in the y direction. (same as in last call to [[db2ink]])
real(wp),dimension(nx,ny),intent(in) :: bcoef !! the b-spline coefficients computed by [[db2ink]].
real(wp),intent(out) :: f !! interpolated value
integer,intent(out) :: iflag !! status flag: 0 : no errors, /=0 : error
integer,intent(inout) :: inbvx !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer :: k, lefty, mflag, kcol
real(wp),dimension(ky) :: temp
real(wp),dimension(3*max(kx,ky)) :: work
f = 0.0_wp
if (xval<tx(1) .or. xval>tx(nx+kx)) then
!write(error_unit,'(A)') 'db2val - x value out of bounds'
iflag = 601
return
end if
if (yval<ty(1) .or. yval>ty(ny+ky)) then
!write(error_unit,'(A)') 'db2val - y value out of bounds'
iflag = 602
return
end if
iflag = -1
call dintrv(ty,ny+ky,yval,iloy,lefty,mflag); if (mflag /= 0) return
kcol = lefty - ky
do k=1,ky
kcol = kcol + 1
call dbvalu(tx,bcoef(:,kcol),nx,kx,idx,xval,inbvx,work,iflag,temp(k))
if (iflag/=0) return !error
end do
kcol = lefty - ky + 1
call dbvalu(ty(kcol:),temp,ky,ky,idy,yval,inbvy,work,iflag,f)
end subroutine db2val
!*****************************************************************************************
!*****************************************************************************************
!> Determines the parameters of a function that interpolates
! the three-dimensional gridded data
! $$ [x(i),y(j),z(k),\mathrm{fcn}(i,j,k)] ~\mathrm{for}~
! i=1,..,n_x ~\mathrm{and}~ j=1,..,n_y, ~\mathrm{and}~ k=1,..,n_z $$
! The interpolating function and
! its derivatives may subsequently be evaluated by the function
! [[db3val]].
!
! The interpolating function is a piecewise polynomial function
! represented as a tensor product of one-dimensional b-splines. the
! form of this function is
! $$ s(x,y,z) = \sum_{i=1}^{n_x} \sum_{j=1}^{n_y} \sum_{k=1}^{n_z}
! a_{ijk} u_i(x) v_j(y) w_k(z) $$
!
! where the functions \(u_i\), \(v_j\), and \(w_k\) are one-dimensional b-
! spline basis functions. the coefficients \(a_{ijk}\) are chosen so that:
!
! $$ s(x(i),y(j),z(k)) = \mathrm{fcn}(i,j,k)
! ~\mathrm{for}~ i=1,..,n_x , j=1,..,n_y , k=1,..,n_z $$
!
! Note that for fixed values of y and z s(x,y,z) is a piecewise
! polynomial function of x alone, for fixed values of x and z s(x,y,z)
! is a piecewise polynomial function of y alone, and for fixed
! values of x and y s(x,y,z) is a function of z alone. in one
! dimension a piecewise polynomial may be created by partitioning a
! given interval into subintervals and defining a distinct polynomial
! piece on each one. the points where adjacent subintervals meet are
! called knots. each of the functions \(u_i\), \(v_j\), and \(w_k\) above is a
! piecewise polynomial.
!
! Users of db3ink choose the order (degree+1) of the polynomial
! pieces used to define the piecewise polynomial in each of the x, y,
! and z directions (kx, ky, and kz). users also may define their own
! knot sequence in x, y, and z separately (tx, ty, and tz). if iflag=
! 0, however, db3ink will choose sequences of knots that result in a
! piecewise polynomial interpolant with kx-2 continuous partial
! derivatives in x, ky-2 continuous partial derivatives in y, and kz-
! 2 continuous partial derivatives in z. (kx knots are taken near
! each endpoint in x, not-a-knot end conditions are used, and the
! remaining knots are placed at data points if kx is even or at
! midpoints between data points if kx is odd. the y and z directions
! are treated similarly.)
!
! After a call to db3ink, all information necessary to define the
! interpolating function are contained in the parameters nx, ny, nz,
! kx, ky, kz, tx, ty, tz, and bcoef. these quantities should not be
! altered until after the last call of the evaluation routine [[db3val]].
!
!# History
!
! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.
! * JEC : 000330 modified array declarations.
! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.
pure subroutine db3ink(x,nx,y,ny,z,nz,fcn,kx,ky,kz,iknot,tx,ty,tz,bcoef,iflag)
implicit none
integer,intent(in) :: nx !! number of x abcissae (>= 3)
integer,intent(in) :: ny !! number of y abcissae (>= 3)
integer,intent(in) :: nz !! number of z abcissae (>= 3)
integer,intent(in) :: kx !! the order of spline pieces in x (>= 2, < nx). (order = polynomial degree + 1)
integer,intent(in) :: ky !! the order of spline pieces in y (>= 2, < ny). (order = polynomial degree + 1)
integer,intent(in) :: kz !! the order of spline pieces in z (>= 2, < nz). (order = polynomial degree + 1)
real(wp),dimension(:),intent(in) :: x !! `nx` array of x abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: y !! `ny` array of y abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: z !! `nz` array of z abcissae. must be strictly increasing.
real(wp),dimension(:,:,:),intent(in) :: fcn !! `(nx,ny,nz)` matrix of function values to interpolate. fcn(i,j,k) should
!! contain the function value at the point (x(i),y(j),z(k))
integer,intent(in) :: iknot !! 0 = knot sequence chosen by [[db1ink]].
!! 1 = knot sequence chosen by user.
real(wp),dimension(:),intent(inout) :: tx !! The `nx+kx` knots in the `x` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db3ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: ty !! The `ny+ky` knots in the `y` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db3ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: tz !! The `nz+kz` knots in the `z` direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db3ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:,:,:),intent(out) :: bcoef !! '(nx,ny,nz)' matrix of coefficients of the b-spline interpolant.
integer,intent(out) :: iflag !! 0 = successful execution.
!! 2 = iknot out of range.
!! 3 = nx out of range.
!! 4 = kx out of range.
!! 5 = x not strictly increasing.
!! 6 = tx not non-decreasing.
!! 7 = ny out of range.
!! 8 = ky out of range.
!! 9 = y not strictly increasing.
!! 10 = ty not non-decreasing.
!! 11 = nz out of range.
!! 12 = kz out of range.
!! 13 = z not strictly increasing.
!! 14 = ty not non-decreasing.
!! 700 = size(x) /= size(fcn,1).
!! 701 = size(y) /= size(fcn,2).
!! 702 = size(z) /= size(fcn,3).
!! 706 = size(x) /= nx.
!! 707 = size(y) /= ny.
!! 708 = size(z) /= nz.
!! 712 = size(tx) /= nx+kx.
!! 713 = size(ty) /= ny+ky.
!! 714 = size(tz) /= nz+kz.
!! 800 = size(x) /= size(bcoef,1).
!! 801 = size(y) /= size(bcoef,2).
!! 802 = size(z) /= size(bcoef,3).
real(wp),dimension(nx*ny*nz) :: temp
real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1),2*kz*(nz+1))) :: work
logical :: status_ok
! check validity of input
call check_inputs('db3ink',&
iknot,&
iflag,&
nx=nx,ny=ny,nz=nz,&
kx=kx,ky=ky,kz=kz,&
x=x,y=y,z=z,&
tx=tx,ty=ty,tz=tz,&
f3=fcn,&
bcoef3=bcoef,&
status_ok=status_ok)
if (status_ok) then
! choose knots
if (iknot == 0) then
call dbknot(x,nx,kx,tx)
call dbknot(y,ny,ky,ty)
call dbknot(z,nz,kz,tz)
end if
! copy fcn to work in packed for dbtpcf
temp(1:nx*ny*nz) = reshape( fcn, [nx*ny*nz] )
! construct b-spline coefficients
call dbtpcf(x,nx,temp, nx,ny*nz,tx,kx,bcoef,work,iflag)
if (iflag==0) call dbtpcf(y,ny,bcoef,ny,nx*nz,ty,ky,temp, work,iflag)
if (iflag==0) call dbtpcf(z,nz,temp, nz,nx*ny,tz,kz,bcoef,work,iflag)
end if
end subroutine db3ink
!*****************************************************************************************
!*****************************************************************************************
!> Evaluates the tensor product piecewise polynomial
! interpolant constructed by the routine [[db3ink]] or one of its
! derivatives at the point (xval,yval,zval).
!
! To evaluate the
! interpolant itself, set idx=idy=idz=0, to evaluate the first
! partial with respect to x, set idx=1,idy=idz=0, and so on.
!
! db3val returns 0.0 if (xval,yval,zval) is out of range. that is,
!```fortran
! xval<tx(1) .or. xval>tx(nx+kx) .or.
! yval<ty(1) .or. yval>ty(ny+ky) .or.
! zval<tz(1) .or. zval>tz(nz+kz)
!```
! if the knots tx, ty, and tz were chosen by [[db3ink]], then this is
! equivalent to
!```fortran
! xval<x(1) .or. xval>x(nx)+epsx .or.
! yval<y(1) .or. yval>y(ny)+epsy .or.
! zval<z(1) .or. zval>z(nz)+epsz
!```
! where
!```fortran
! epsx = 0.1*(x(nx)-x(nx-1))
! epsy = 0.1*(y(ny)-y(ny-1))
! epsz = 0.1*(z(nz)-z(nz-1))
!```
!
! The input quantities tx, ty, tz, nx, ny, nz, kx, ky, kz, and bcoef
! should remain unchanged since the last call of [[db3ink]].
!
!# History
!
! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.
! * JEC : 000330 modified array declarations.
! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.
pure subroutine db3val(xval,yval,zval,idx,idy,idz,&
tx,ty,tz,&
nx,ny,nz,kx,ky,kz,bcoef,f,iflag,&
inbvx,inbvy,inbvz,iloy,iloz)
implicit none
integer,intent(in) :: idx !! x derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idy !! y derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idz !! z derivative of piecewise polynomial to evaluate.
integer,intent(in) :: nx !! the number of interpolation points in x. (same as in last call to [[db3ink]])
integer,intent(in) :: ny !! the number of interpolation points in y. (same as in last call to [[db3ink]])
integer,intent(in) :: nz !! the number of interpolation points in z. (same as in last call to [[db3ink]])
integer,intent(in) :: kx !! order of polynomial pieces in x. (same as in last call to [[db3ink]])
integer,intent(in) :: ky !! order of polynomial pieces in y. (same as in last call to [[db3ink]])
integer,intent(in) :: kz !! order of polynomial pieces in z. (same as in last call to [[db3ink]])
real(wp),intent(in) :: xval !! x coordinate of evaluation point.
real(wp),intent(in) :: yval !! y coordinate of evaluation point.
real(wp),intent(in) :: zval !! z coordinate of evaluation point.
real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial in the x direction. (same as in last call to [[db3ink]])
real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial in the y direction. (same as in last call to [[db3ink]])
real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial in the z direction. (same as in last call to [[db3ink]])
real(wp),dimension(nx,ny,nz),intent(in) :: bcoef !! the b-spline coefficients computed by [[db3ink]].
real(wp),intent(out) :: f !! interpolated value
integer,intent(out) :: iflag !! status flag: 0 : no errors, /=0 : error
integer,intent(inout) :: inbvx !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvz !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloz !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
real(wp),dimension(ky,kz) :: temp1
real(wp),dimension(kz) :: temp2
real(wp),dimension(3*max(kx,ky,kz)) :: work
integer :: lefty, leftz, mflag,&
kcoly, kcolz, j, k
f = 0.0_wp
if (xval<tx(1) .or. xval>tx(nx+kx)) then
!write(error_unit,'(A)') 'db3val - x value out of bounds'
iflag = 601
return
end if
if (yval<ty(1) .or. yval>ty(ny+ky)) then
!write(error_unit,'(A)') 'db3val - y value out of bounds'
iflag = 602
return
end if
if (zval<tz(1) .or. zval>tz(nz+kz)) then
!write(error_unit,'(A)') 'db3val - z value out of bounds'
iflag = 603
return
end if
iflag = -1
call dintrv(ty,ny+ky,yval,iloy,lefty,mflag); if (mflag /= 0) return
call dintrv(tz,nz+kz,zval,iloz,leftz,mflag); if (mflag /= 0) return
iflag = 0
kcolz = leftz - kz
do k=1,kz
kcolz = kcolz + 1
kcoly = lefty - ky
do j=1,ky
kcoly = kcoly + 1
call dbvalu(tx,bcoef(:,kcoly,kcolz),nx,kx,idx,xval,inbvx,work,iflag,temp1(j,k))
if (iflag/=0) return
end do
end do
kcoly = lefty - ky + 1
do k=1,kz
call dbvalu(ty(kcoly:),temp1(:,k),ky,ky,idy,yval,inbvy,work,iflag,temp2(k))
if (iflag/=0) return
end do
kcolz = leftz - kz + 1
call dbvalu(tz(kcolz:),temp2,kz,kz,idz,zval,inbvz,work,iflag,f)
end subroutine db3val
!*****************************************************************************************
!*****************************************************************************************
!> Determines the parameters of a function that interpolates
! the four-dimensional gridded data
! $$ [x(i),y(j),z(k),q(l),\mathrm{fcn}(i,j,k,l)] ~\mathrm{for}~
! i=1,..,n_x ~\mathrm{and}~ j=1,..,n_y, ~\mathrm{and}~ k=1,..,n_z,
! ~\mathrm{and}~ l=1,..,n_q $$
! The interpolating function and its derivatives may
! subsequently be evaluated by the function [[db4val]].
!
! See [[db3ink]] header for more details.
!
!# History
!
! * Jacob Williams, 2/24/2015 : Created this routine.
pure subroutine db4ink(x,nx,y,ny,z,nz,q,nq,&
fcn,&
kx,ky,kz,kq,&
iknot,&
tx,ty,tz,tq,&
bcoef,iflag)
implicit none
integer,intent(in) :: nx !! number of x abcissae (>= 3)
integer,intent(in) :: ny !! number of y abcissae (>= 3)
integer,intent(in) :: nz !! number of z abcissae (>= 3)
integer,intent(in) :: nq !! number of q abcissae (>= 3)
integer,intent(in) :: kx !! the order of spline pieces in x (>= 2, < nx). (order = polynomial degree + 1)
integer,intent(in) :: ky !! the order of spline pieces in y (>= 2, < ny). (order = polynomial degree + 1)
integer,intent(in) :: kz !! the order of spline pieces in z (>= 2, < nz). (order = polynomial degree + 1)
integer,intent(in) :: kq !! the order of spline pieces in q (>= 2, < nq). (order = polynomial degree + 1)
real(wp),dimension(:),intent(in) :: x !! `nx` array of x abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: y !! `ny` array of y abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: z !! `nz` array of z abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: q !! `nq` array of q abcissae. must be strictly increasing.
real(wp),dimension(:,:,:,:),intent(in) :: fcn !! `(nx,ny,nz,nq)` matrix of function values to interpolate. fcn(i,j,k,q) should
!! contain the function value at the point (x(i),y(j),z(k),q(l))
integer,intent(in) :: iknot !! 0 = knot sequence chosen by [[db1ink]].
!! 1 = knot sequence chosen by user.
real(wp),dimension(:),intent(inout) :: tx !! The `nx+kx` knots in the x direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db4ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: ty !! The `ny+ky` knots in the y direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db4ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: tz !! The `nz+kz` knots in the z direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db4ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: tq !! The `nq+kq` knots in the q direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db4ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:,:,:,:),intent(out) :: bcoef !! `(nx,ny,nz,nq)` matrix of coefficients of the b-spline interpolant.
integer,intent(out) :: iflag !! 0 = successful execution.
!! 2 = iknot out of range.
!! 3 = nx out of range.
!! 4 = kx out of range.
!! 5 = x not strictly increasing.
!! 6 = tx not non-decreasing.
!! 7 = ny out of range.
!! 8 = ky out of range.
!! 9 = y not strictly increasing.
!! 10 = ty not non-decreasing.
!! 11 = nz out of range.
!! 12 = kz out of range.
!! 13 = z not strictly increasing.
!! 14 = tz not non-decreasing.
!! 15 = nq out of range.
!! 16 = kq out of range.
!! 17 = q not strictly increasing.
!! 18 = tq not non-decreasing.
!! 700 = size(x) /= size(fcn,1).
!! 701 = size(y) /= size(fcn,2).
!! 702 = size(z) /= size(fcn,3).
!! 703 = size(q) /= size(fcn,4).
!! 706 = size(x) /= nx.
!! 707 = size(y) /= ny.
!! 708 = size(z) /= nz.
!! 709 = size(q) /= nq.
!! 712 = size(tx) /= nx+kx.
!! 713 = size(ty) /= ny+ky.
!! 714 = size(tz) /= nz+kz.
!! 715 = size(tq) /= nq+kq.
!! 800 = size(x) /= size(bcoef,1).
!! 801 = size(y) /= size(bcoef,2).
!! 802 = size(z) /= size(bcoef,3).
!! 803 = size(q) /= size(bcoef,4).
real(wp),dimension(nx*ny*nz*nq) :: temp
real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1),2*kz*(nz+1),2*kq*(nq+1))) :: work
logical :: status_ok
! check validity of input
call check_inputs('db4ink',&
iknot,&
iflag,&
nx=nx,ny=ny,nz=nz,nq=nq,&
kx=kx,ky=ky,kz=kz,kq=kq,&
x=x,y=y,z=z,q=q,&
tx=tx,ty=ty,tz=tz,tq=tq,&
f4=fcn,&
bcoef4=bcoef,&
status_ok=status_ok)
if (status_ok) then
! choose knots
if (iknot == 0) then
call dbknot(x,nx,kx,tx)
call dbknot(y,ny,ky,ty)
call dbknot(z,nz,kz,tz)
call dbknot(q,nq,kq,tq)
end if
! construct b-spline coefficients
call dbtpcf(x,nx,fcn, nx,ny*nz*nq,tx,kx,temp, work,iflag)
if (iflag==0) call dbtpcf(y,ny,temp, ny,nx*nz*nq,ty,ky,bcoef,work,iflag)
if (iflag==0) call dbtpcf(z,nz,bcoef,nz,nx*ny*nq,tz,kz,temp, work,iflag)
if (iflag==0) call dbtpcf(q,nq,temp, nq,nx*ny*nz,tq,kq,bcoef,work,iflag)
end if
end subroutine db4ink
!*****************************************************************************************
!*****************************************************************************************
!> Evaluates the tensor product piecewise polynomial
! interpolant constructed by the routine [[db4ink]] or one of its
! derivatives at the point (xval,yval,zval,qval).
!
! To evaluate the
! interpolant itself, set idx=idy=idz=idq=0, to evaluate the first
! partial with respect to x, set idx=1,idy=idz=idq=0, and so on.
!
! See [[db3val]] header for more information.
!
!# History
!
! * Jacob Williams, 2/24/2015 : Created this routine.
pure subroutine db4val(xval,yval,zval,qval,&
idx,idy,idz,idq,&
tx,ty,tz,tq,&
nx,ny,nz,nq,&
kx,ky,kz,kq,&
bcoef,f,iflag,&
inbvx,inbvy,inbvz,inbvq,iloy,iloz,iloq)
implicit none
integer,intent(in) :: idx !! x derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idy !! y derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idz !! z derivative of piecewise polynomial to evaluate.
integer,intent(in) :: idq !! q derivative of piecewise polynomial to evaluate.
integer,intent(in) :: nx !! the number of interpolation points in x. (same as in last call to [[db4ink]])
integer,intent(in) :: ny !! the number of interpolation points in y. (same as in last call to [[db4ink]])
integer,intent(in) :: nz !! the number of interpolation points in z. (same as in last call to [[db4ink]])
integer,intent(in) :: nq !! the number of interpolation points in q. (same as in last call to [[db4ink]])
integer,intent(in) :: kx !! order of polynomial pieces in x. (same as in last call to [[db4ink]])
integer,intent(in) :: ky !! order of polynomial pieces in y. (same as in last call to [[db4ink]])
integer,intent(in) :: kz !! order of polynomial pieces in z. (same as in last call to [[db4ink]])
integer,intent(in) :: kq !! order of polynomial pieces in q. (same as in last call to [[db4ink]])
real(wp),intent(in) :: xval !! x coordinate of evaluation point.
real(wp),intent(in) :: yval !! y coordinate of evaluation point.
real(wp),intent(in) :: zval !! z coordinate of evaluation point.
real(wp),intent(in) :: qval !! q coordinate of evaluation point.
real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial in the x direction. (same as in last call to [[db4ink]])
real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial in the y direction. (same as in last call to [[db4ink]])
real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial in the z direction. (same as in last call to [[db4ink]])
real(wp),dimension(nq+kq),intent(in) :: tq !! sequence of knots defining the piecewise polynomial in the q direction. (same as in last call to [[db4ink]])
real(wp),dimension(nx,ny,nz,nq),intent(in) :: bcoef !! the b-spline coefficients computed by [[db4ink]].
real(wp),intent(out) :: f !! interpolated value
integer,intent(out) :: iflag !! status flag: 0 : no errors, /=0 : error
integer,intent(inout) :: inbvx !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvz !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: inbvq !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloy !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloz !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
integer,intent(inout) :: iloq !! initialization parameter which must be set to 1 the first time this routine is called, and must not be changed by the user.
real(wp),dimension(ky,kz,kq) :: temp1
real(wp),dimension(kz,kq) :: temp2
real(wp),dimension(kq) :: temp3
real(wp),dimension(3*max(kx,ky,kz,kq)) :: work
integer :: lefty, leftz, leftq, mflag,&
kcoly, kcolz, kcolq, j, k, q
f = 0.0_wp
if (xval<tx(1) .or. xval>tx(nx+kx)) then
!write(error_unit,'(A)') 'db4val - x value out of bounds'
iflag = 601
return
end if
if (yval<ty(1) .or. yval>ty(ny+ky)) then
!write(error_unit,'(A)') 'db4val - y value out of bounds'
iflag = 602
return
end if
if (zval<tz(1) .or. zval>tz(nz+kz)) then
!write(error_unit,'(A)') 'db4val - z value out of bounds'
iflag = 603
return
end if
if (qval<tq(1) .or. qval>tq(nq+kq) ) then
!write(error_unit,'(A)') 'db4val - q value out of bounds'
iflag = 604
return
end if
iflag = -1
call dintrv(ty,ny+ky,yval,iloy,lefty,mflag); if (mflag /= 0) return
call dintrv(tz,nz+kz,zval,iloz,leftz,mflag); if (mflag /= 0) return
call dintrv(tq,nq+kq,qval,iloq,leftq,mflag); if (mflag /= 0) return
iflag = 0
! x -> y, z, q
kcolq = leftq - kq
do q=1,kq
kcolq = kcolq + 1
kcolz = leftz - kz
do k=1,kz
kcolz = kcolz + 1
kcoly = lefty - ky
do j=1,ky
kcoly = kcoly + 1
call dbvalu(tx,bcoef(:,kcoly,kcolz,kcolq),&
nx,kx,idx,xval,inbvx,work,iflag,temp1(j,k,q))
if (iflag/=0) return
end do
end do
end do
! y -> z, q
kcoly = lefty - ky + 1
do q=1,kq
do k=1,kz
call dbvalu(ty(kcoly:),temp1(:,k,q),ky,ky,idy,yval,inbvy,work,iflag,temp2(k,q))
if (iflag/=0) return
end do
end do
! z -> q
kcolz = leftz - kz + 1
do q=1,kq
call dbvalu(tz(kcolz:),temp2(:,q),kz,kz,idz,zval,inbvz,work,iflag,temp3(q))
if (iflag/=0) return
end do
! q
kcolq = leftq - kq + 1
call dbvalu(tq(kcolq:),temp3,kq,kq,idq,qval,inbvq,work,iflag,f)
end subroutine db4val
!*****************************************************************************************
!*****************************************************************************************
!> Determines the parameters of a function that interpolates
! the five-dimensional gridded data (x(i),y(j),z(k),q(l),r(m),fcn(i,j,k,l,m)) for
! i=1,..,nx, j=1,..,ny, k=1,..,nz, l=1,..,nq, and m=1,..,nr.
! The interpolating function and its derivatives may subsequently be evaluated
! by the function [[db5val]].
!
! See [[db3ink]] header for more details.
!
!# History
!
! * Jacob Williams, 2/24/2015 : Created this routine.
pure subroutine db5ink(x,nx,y,ny,z,nz,q,nq,r,nr,&
fcn,&
kx,ky,kz,kq,kr,&
iknot,&
tx,ty,tz,tq,tr,&
bcoef,iflag)
implicit none
integer,intent(in) :: nx !! number of x abcissae (>= 3)
integer,intent(in) :: ny !! number of y abcissae (>= 3)
integer,intent(in) :: nz !! number of z abcissae (>= 3)
integer,intent(in) :: nq !! number of q abcissae (>= 3)
integer,intent(in) :: nr !! number of r abcissae (>= 3)
integer,intent(in) :: kx !! the order of spline pieces in x (>= 2, < nx). (order = polynomial degree + 1)
integer,intent(in) :: ky !! the order of spline pieces in y (>= 2, < ny). (order = polynomial degree + 1)
integer,intent(in) :: kz !! the order of spline pieces in z (>= 2, < nz). (order = polynomial degree + 1)
integer,intent(in) :: kq !! the order of spline pieces in q (>= 2, < nq). (order = polynomial degree + 1)
integer,intent(in) :: kr !! the order of spline pieces in r (>= 2, < nr). (order = polynomial degree + 1)
real(wp),dimension(:),intent(in) :: x !! `nx` array of x abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: y !! `ny` array of y abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: z !! `nz` array of z abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: q !! `nq` array of q abcissae. must be strictly increasing.
real(wp),dimension(:),intent(in) :: r !! `nr` array of r abcissae. must be strictly increasing.
real(wp),dimension(:,:,:,:,:),intent(in) :: fcn !! `(nx,ny,nz,nq,nr)` matrix of function values to interpolate. fcn(i,j,k,q,r) should
!! contain the function value at the point (x(i),y(j),z(k),q(l),r(m))
integer,intent(in) :: iknot !! 0 = knot sequence chosen by [[db1ink]].
!! 1 = knot sequence chosen by user.
real(wp),dimension(:),intent(inout) :: tx !! The `nx+kx` knots in the x direction for the spline interpolant.
!! If `iknot=0` these are chosen by [[db5ink]].
!! If `iknot=1` these are specified by the user.
!! Must be non-decreasing.
real(wp),dimension(:),intent(inout) :: ty !! The `ny+ky` knots in the y direction for the spline interpolant.