4.8.3.4. CUBSPL
Language type |
SubRoutine |
FORTRAN |
call rd_cubspl(xval, zval, identity, order, array, errflg) or cubspl(xval, zval, identity, order, array, errflg) |
C/C++ |
rd_cubspl(xval, zval, identity, order, &array[0], &errflg) or cubspl(xval, zval, identity, order, &array[0], &errflg) |
VariableName |
Size |
Description |
xval |
double |
An input variable for the CUBSPL function.
|
zval |
double |
An input variable for the CUBSPL function.
\(\begin{aligned} & \begin{matrix} \left\{ \begin{matrix} {{y}_{1}}=f(x,{{z}_{1}}) \\ {{y}_{2}}=f(x,{{z}_{2}}) \\ \end{matrix} \right., & {{z}_{1}}<z<{{z}_{2}} \\ \end{matrix} \\ & y={{y}_{1}}+\frac{(z-{{z}_{1}})({{y}_{2}}-{{y}_{1}})}{{{z}_{2}}-{{z}_{1}}} \\ \end{aligned}\) |
identity |
double |
The identity of Spline. |
order |
int |
The interpolation methods for the functions (return the value if 0, return calculation for 1st order differential equation if 1, and return calculation for 2nd order differential equation if 2)
|
array |
double |
|
errflg |
int |
Error flag. If the result of this argument is zero, there’s no error |
C---- SUB. MOTION_USUB
SUBROUTINE MOTION_USUB
& (TIME,UPAR,NPAR,IORD,IFLAG,RESULT)
C---- TO EXPORT * SUBROUTINE
!DEC$ ATTRIBUTES DLLEXPORT,C::MOTION_USUB
C---- INCLUDE SYSTEM CALL
INCLUDE 'SYSCAL.F'
C---- DEFINE VARIABLES
C Parameter Information
C TIME : Simulation time of RD/Solver. (Input)
C UPAR : Parameters defined by user. (Input)
C NPAR : Number of user parameters. (Input)
C IORD : Integrator order. (Input)
C IFLAG : When RD/Solver initializes arrays, the flag is true. (Input)
C RESULT : Returned value. (Output)
DOUBLE PRECISION TIME, UPAR(*)
INTEGER NPAR, IORD
LOGICAL IFLAG
DOUBLE PRECISION RESULT[REFERENCE]
C---- USER STATEMENT
C---- Local Variable Definition
double precision result_order(1)
double precision result_order0(1)
double precision result_order1(1)
double precision result_order2(1)
integer splineID
integer iorder
integer iflagRest
logical ERRFLG
integer errorID
C---- Assign Parameter
splineID = int(UPAR(1))
iorder = int(UPAR(2))
iflagTest = int(UPAR(3))
C---- Call RD_CUBSPL to get the result of spline
if (iflagTest) then
call RD_CUBSPL(time,0,splineID,0,result_order0(1),ERRFLG)
errorID = 1000
call ERRMES(ERRFLG,'Error : order 0',errorID,'CUBSPL')
call RD_CUBSPL(time,0,splineID,1,result_order1(1),ERRFLG)
errorID = 1001
call ERRMES(ERRFLG,'Error : order 1',errorID,'CUBSPL')
call RD_CUBSPL(time,0,splineID,2,result_order2(1),ERRFLG)
errorID = 1002
call ERRMES(ERRFLG,'Error : order 2',errorID,'CUBSPL')
C------- Assign the returned value to User Subroutine
if (iorder .eq. 0) then
RESULT = result_order0(1)
else if (iorder .eq. 1) then
RESULT = result_order1(1)
else if (ioerder .eq. 2) then
RESULT = result_order2(1)
endif
else
call RD_CUBSPL(time,0,splineID,iorder,result_order(1),ERRFLG)
errorID = 2000
call ERRMES(ERRFLG,'Error : order',errorID,'CUBSPL')
C------- Assign the returned value to User Subroutine
RESULT = result_order(1)
endif
RETURN
END
#include "stdafx.h"
#include "DllFunc.h"
Cubspl_C_API void __cdecl motion_usub
(double time, double upar[], int npar, int iord, int iflag, double* result)
{
using namespace rd_syscall;
// Parameter Information
// time : Simulation time of RD/Solver. (Input)
// upar : Parameters defined by user. (Input)
// npar : Number of user parameters. (Input)
// iord : Integrator order. (Input)
// iflag : When RD/Solver initializes arrays, the flag is true. (Input)
// result : Returned value. (Output)
// User Statement
// Local Variable Definition
double result_order0 = 0.0;
double result_order1 = 0.0;
double result_order2 = 0.0;
int splineID;
int iorder = 0;
int iflagTest = 0;
int ERRFLG = 0;
int errorID = 0;
// Assign Parameters
splineID = (int)upar[0];
iorder = (int)upar[1];
iflagTest = (int)upar[2];
// Call RD_CUBSPL to collect information for calculations
if (iflagTest)
{
rd_cubspl(time,0,splineID,0,&result_order0,&ERRFLG);
errorID = 1000;
errmes(ERRFLG,"Error : order 0",errorID,"CUBSPL");
rd_cubspl(time,0,splineID,1,&result_order1,&ERRFLG);
errorID = 1001;
errmes(ERRFLG,"Error : order 1",errorID,"CUBSPL");
rd_cubspl(time,0,splineID,2,&result_order2,&ERRFLG);
errorID = 1002;
errmes(ERRFLG,"Error : order 2",errorID,"CUBSPL");
// Assign the returned value to User Subroutine
if (iorder == 0)
{
*result = result_order0;
}
else if (iorder == 1)
{
*result = result_order1;
}
else if (iorder ==2)
{
*result = result_order2;
}
}
else
{
// Assign the returned value to User Subroutine
rd_cubspl(time,0,splineID,iorder,result,&ERRFLG);
errorID = 2000;
errmes(ERRFLG,"Error : order",errorID,"CUBSPL");
}
}