PDA

View Full Version : 3-dimension interpolation



li1991
06-19-2008, 08:18 AM
Has anyone used the 3-dimension interpolation tools such as bs3in? I typed in exactly the same codes as those in the IMSL Math/Library documention for the routine. Here is the error I got when running the code.

*** TERMINAL ERROR 1 from BS3IN. The order of the spline in the X direction
*** must be at least 1 while KXORD = 0 is given.

*** TERMINAL ERROR 2 from BS3IN. The order of the spline in the Y direction
*** must be at least 1 while KYORD = 0 is given.
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
Unknown B6055A34 Unknown Unknown Unknown
test_bs3gd.o 0804D322 Unknown Unknown Unknown
test_bs3gd.o 0804C848 Unknown Unknown Unknown
Unknown B5CA979D Unknown Unknown Unknown
test_bs3gd.o 0804C701 Unknown Unknown Unknown


Does anyone know what is going on?

Thank you.

Lee

pate
06-19-2008, 09:09 AM
I tried the example from that routine and it works fine, so the code is correct in the IMSL PDF Help file. Make sure you are copying-and-pasting the text in correctly into your code. Also, make sure the IMSL library you are linking to is the correct one for the version of your compiler. Finally, if you are doing this from a command line run the ifortvars.bat file to setup the Intel environment for command line use.

Here is the code I used:


USE BS3IN_INT
USE BSNAK_INT

USE UMACH_INT
USE BS3GD_INT
IMPLICIT NONE

! SPECIFICATIONS FOR PARAMETERS
INTEGER KXORD, KYORD, KZORD, LDF, MDF, NXDATA, NXKNOT, NXVEC,&
NYDATA, NYKNOT, NYVEC, NZDATA, NZKNOT, NZVEC
PARAMETER (KXORD=5, KYORD=2, KZORD=3, NXDATA=21, NXVEC=4,&
NYDATA=6, NYVEC=4, NZDATA=8, NZVEC=2, LDF=NXDATA,&
MDF=NYDATA, NXKNOT=NXDATA+KXORD, NYKNOT=NYDATA+KYORD,&
NZKNOT=NZDATA+KZORD)

INTEGER I, J, K, NOUT, NXCOEF, NYCOEF, NZCOEF
REAL BSCOEF(NXDATA,NYDATA,NZDATA), F,&
FDATA(LDF,MDF,NZDATA), FLOAT, VALUE(NXVEC,NYVEC,NZVEC)&
, X, XDATA(NXDATA), XKNOT(NXKNOT), XVEC(NXVEC), Y,&
YDATA(NYDATA), YKNOT(NYKNOT), YVEC(NYVEC), Z,&
ZDATA(NZDATA), ZKNOT(NZKNOT), ZVEC(NZVEC)
INTRINSIC FLOAT

! Define function.
F(X,Y,Z) = X*X*X + X*Y*Z
! Set up X-interpolation points

DO 10 I=1, NXDATA
XDATA(I) = FLOAT(I-11)/10.0
10 CONTINUE

! Set up Y-interpolation points
DO 20 I=1, NYDATA
YDATA(I) = FLOAT(I-1)/FLOAT(NYDATA-1)
20 CONTINUE

! Set up Z-interpolation points
DO 30 I=1, NZDATA
ZDATA(I) = FLOAT(I-1)/FLOAT(NZDATA-1)
30 CONTINUE

! Generate knots
CALL BSNAK (NXDATA, XDATA, KXORD, XKNOT)
CALL BSNAK (NYDATA, YDATA, KYORD, YKNOT)
CALL BSNAK (NZDATA, ZDATA, KZORD, ZKNOT)

! Generate FDATA
DO 50 K=1, NZDATA
DO 40 I=1, NYDATA
DO 40 J=1, NXDATA
FDATA(J,I,K) = F(XDATA(J),YDATA(I),ZDATA(K))
! 989 Continue
40 CONTINUE
50 CONTINUE

! Get output unit number
CALL UMACH (2, NOUT)

! Interpolate
CALL BS3IN (XDATA, YDATA, ZDATA, FDATA, KXORD, &
KYORD, KZORD, XKNOT, YKNOT, ZKNOT, BSCOEF)

NXCOEF = NXDATA
NYCOEF = NYDATA
NZCOEF = NZDATA

! Write heading
WRITE (NOUT,99999)

! Print over a grid of
! [-1.0,1.0] x [0.0,1.0] x [0.0,1.0]
! at 32 points.
DO 60 I=1, NXVEC
XVEC(I) = 2.0*(FLOAT(I-1)/3.0) - 1.0
60 CONTINUE

DO 70 I=1, NYVEC
YVEC(I) = FLOAT(I-1)/3.0
70 CONTINUE

DO 80 I=1, NZVEC
ZVEC(I) = FLOAT(I-1)
80 CONTINUE

! Call the evaluation routine.
CALL BS3GD (0, 0, 0, XVEC, YVEC, ZVEC,&
KXORD, KYORD, KZORD, XKNOT, YKNOT, ZKNOT, BSCOEF, VALUE)

DO 110 I=1, NXVEC
DO 100 J=1, NYVEC
DO 90 K=1, NZVEC
WRITE (NOUT,'(4F13.4, F13.6)') XVEC(I), YVEC(K),&
ZVEC(K), VALUE(I,J,K),&
F(XVEC(I),YVEC(J),ZVEC(K))&
- VALUE(I,J,K)
90 CONTINUE
100 CONTINUE
110 CONTINUE

99999 FORMAT (10X, 'X', 11X, 'Y', 10X, 'Z', 10X, 'S(X,Y,Z)', 7X, 'Error')

END

li1991
06-19-2008, 12:39 PM
Thanks for the reply. Although the BS3IN routine still does not work, I did manage to get B23IN to work, which suggets to me that maybe in passing the vectors around, the machine is confused about the dimension of the vectors (BS3IN does not specify the dimensions). This is strange because I am using Fortran 90 not Fortran 77.

Lee

pate
06-19-2008, 01:49 PM
Make sure you have the correct version of IMSL for your compiler and O/S. Which compiler and version are you using and which IMSL CD did you install from?

evahepburn
01-23-2014, 06:36 PM
I had the same problem. I fed in the value of kxord properly, but the message `The order of the spline in the Y direction
*** must be at least 1 while KYORD = 0 is given.' kept popping up. I tried b22in as suggested by a post but still it does not work. I would appreciate any help.

mecej4
01-27-2014, 10:04 AM
I had the same problem. I fed in the value of kxord properly, but the message `The order of the spline in the Y direction
*** must be at least 1 while KYORD = 0 is given.' kept popping up. I tried b22in as suggested by a post but still it does not work. I would appreciate any help.

Please provide information about (i) the version of IMSL used, including OS/Platform (ii) the compiler used and the command line or IDE options used, and (iii) the source code (either post example code or give accessible link/reference).

evahepburn
02-04-2014, 06:16 PM
Please provide information about (i) the version of IMSL used, including OS/Platform (ii) the compiler used and the command line or IDE options used, and (iii) the source code (either post example code or give accessible link/reference).

Thanks a lot for the reply! I am not sure about the answers as I was running the program on the campus server. The environment I set on linux was

setenv PATH "${PATH}:/opt/intel/composerxe-2011/bin/intel64"
source /opt/intel/composerxe-2011.1.107/bin/compilervars.csh intel64
source /usr/local/vni/imsl/fnl701/lnxin121e64/bin/fnlsetup.csh

evahepburn
02-05-2014, 08:30 AM
Here is the code for the subroutine of interpolation


! First I divide variables k and b into 30 grids respectively .
!SPECIFY GRID VALUES


subroutine compute_grid
k_num = 30
b_num = 30
b_inf = -.45d+0
b_sup = 0.0d+0

k_inf =0.0d+0
k_sup =1.5d+0

do i=1,30
b_grid(i) = b_inf + (b_sup - b_inf) * (i-1) / (b_num - 1)
end do

do i=1,30
k_grid(i) = k_inf + (k_sup - k_inf) * (i-1) / (k_num - 1)
end do


end subroutine


DOUBLE PRECISION function interpolate0(x_b,x_k,x_a)
USE param
DOUBLE PRECISION, INTENT(IN) :: x_b,x_k
INTEGER :: index_a,i,j,KXORD,KYORD,NXDATA,NYDATA,NXKNOT,NYKNO T,NXCOEF,NYCOEF
DOUBLE PRECISION :: BSCOEF(a_num,b_num,k_num),&
value_left, value_right, slope, DBS2IN,DBS2VL ,X,Y,XDATA(1:b_num),YDATA(1:k_num),&
XKNOT(1:b_num+3),YKNOT(1:k_num+3),FDATA0(b_num,k_n um)
external DBSNAK, DBS2VL,DBS2IN,compute_grid


call compute_grid

X = x_b
Y = x_k
! x_b, x_k refer to a specific grid value for b and k, input from the main program

KXORD = 3
KYORD = 3
NYDATA=k_num
NXDATA=b_num
NXCOEF = NXDATA
NYCOEF = NYDATA
NXKNOT=NXDATA + KXORD
NYKNOT=NYDATA + KYORD


do i = 1,b_num
XDATA(i) = b_grid(i)
end do
do j = 1,k_num
YDATA(j) = k_grid(j)
end do

! generate knot sequence, outputs are XKNOT and YKNOT
CALL DBSNAK (NXDATA, XDATA, KXORD, XKNOT)
CALL DBSNAK (NYDATA, YDATA, KYORD, YKNOT)


! FDATA
do i_a = 1,a_num
do i_bj = 1,bj_num
do i_kj = 1,kj_num

FDATA0 = v0_matrix(:,:,i_a,i_bj,i_kj) ! v0_matrix is defined in the main program

end do
end do
end do

BSCOEF = DBS2IN (XDATA, YDATA, FDATA0, KXORD, KYORD, XKNOT, YKNOT,BSCOEF)



if (x_a > a_sup .or. x_a< a_inf) then

interpolate0 = 0

else

interpolate0 = DBS2VL(X,Y,KXORD, KYORD, XKNOT, YKNOT, NXCOEF, NYCOEF, BSCOEF)

end if



end

mecej4
02-06-2014, 01:35 PM
The code that you provided is not complete. In particular, we need the source code for the module PARAM, and we need the declarations for variables such as b_grid().

It would be ideal if you could provide a complete example with enough data to run until we can see the same failure as you did.