C/C++ example for CUBSPL

 

#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");

   }

 

}