4.8.3.91. LINSPL

Table 4.227 Function Name

Language type

Subroutine

FORTRAN

call rd_linspl(xval, zval, identity, order, array, errflg) or linspl(xval, zval, identity, order, array, errflg)

C/C++

rd_linspl(xval, zval, identity, order, &array[0], &errflg) or linspl(xval, zval, identity, order, &array[0], &errflg)

Table 4.228 Parameter information

Variable Name

Size

Description

xval

double

An input variable for the LINSPL function.

  • Generally, this variable is time or a function that returns a real number.

zval

double

An input variable for the LINSPL function.

  • The second variable is necessary for three dimensional spline functions.

  • This variable must be a function that returns a real number. Otherwise, 0 is applied.

    \(\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

int

The id of spline.

order

int

The interpolation method for the functions (return the value if 0, return calculation for 1st order differential equation if 1)

  1. order = 0

    \(array=f(x,spline\_data)\)

  2. order = 1

    \(array=\frac{d}{dx}\left( f(x,spline\_data) \right)\)

array

double

error

logical/int

If an error is encountered in invoking Predefined subroutine, this variable becomes true. This variable must be declared as a logical variable.

Listing 4.98 Fortran code for LINSPL
 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)
       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_LINSPL to get the result of spline
       if (iflagTest) then
         call RD_LINSPL(time,0,splineID,0,result_order0(1),ERRFLG)
         errorID = 1000
         call ERRMES(ERRFLG,'Error : order 0',errorID,'LINSPL')

         call RD_LINSPL(time,0,splineID,1,result_order1(1),ERRFLG)
         errorID = 1001
         call ERRMES(ERRFLG,'Error : order 1',errorID,'LINSPL')

 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)
         endif
       else
         call RD_LINSPL(time,0,splineID,iorder,result_order(1),ERRFLG)
         errorID = 2000
         call ERRMES(ERRFLG,'Error : order',errorID,'LINSPL')

 C------- Assign the returned value to User Subroutine
         RESULT = result_order(1)
       endif

       RETURN
       END
Listing 4.99 C/C++ code for LINSPL
 #include "stdafx.h"
 #include "DllFunc.h"

 Linspl_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;
   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_LINSPL to collect information for calculations
   if (iflagTest)
   {
       rd_linspl(time,0,splineID,0,&result_order0,&ERRFLG);
       errorID = 1000;
       errmes(ERRFLG,"Error : order 0",errorID,"LINSPL");

       rd_linspl(time,0,splineID,1,&result_order1,&ERRFLG);
       errorID = 1001;
       errmes(ERRFLG,"Error : order 1",errorID,"LINSPL");

       // Assign the returned value to User Subroutine
       if (iorder == 0)
       {
         *result = result_order0;
       }
       else if (iorder == 1)
       {
         *result = result_order1;
       }
   }
   else
   {
       // Assign the returned value to User Subroutine
       rd_linspl(time,0,splineID,iorder,result,&ERRFLG);
       errorID = 2000;
       errmes(ERRFLG,"Error : order",errorID,"LINSPL");
   }

 }