Link computational function written in Scilab language

hehiha dungnguyenbk at gmail.com
Wed Jul 11 11:15:51 CEST 2012


Sorry Mike.
I didn't find LibScilab.lib.
I am beginner in scilab. I'm writing external module. 
My module in some case call scilab function. 
My code have macro file and c file. macro file implement scilabfoo function
and c file will call scilabfoo function.
But I didn't know method to do. Could you tell me ?
Here is my code
marco file. EX6.sci 
function r = scilabfoo(x,y)
  r = x + y;
  block_parameter_error(msprintf(gettext("Wrong value for ''%d''."), r), ..
  gettext("Strictly positive integer expected."));
endfunction
function [x, y, typ] = EX6(job, arg1, arg2)

x = []; y = []; typ = [];

  select job
    case 'plot' then
      standard_draw(arg1)

    case 'getinputs' then
      [x, y, typ] = standard_inputs(arg1)

    case 'getoutputs' then
      [x, y, typ] = standard_outputs(arg1)

    case 'getorigin' then
      [x, y] = standard_origin(arg1)

    case 'set' then
      x = arg1;
      graphics = arg1.graphics;
      exprs = graphics.exprs
      model = arg1.model;
                block_parameter_error(msprintf(gettext("Wrong value for
''%s''."), gettext("Input Size")), ..
                gettext("Strictly positive integer expected."));
      while %t do
        [ok, P1, P2, P3, exprs] = getvalue(..
                                                  'Set Parameters',..
                                                  ['parameter 1';..
                                                  'parameter 2';..
                                                  'parameter 3'],..
                                                  list('vec', 1, 'vec', 1,
'vec', 1),..
                                                  exprs)
                                                  

        if ~ok then break, end
          
        model.rpar = [P1; P2; P3]
        graphics.exprs = exprs
        x.graphics = graphics
        x.model = model
        break
      end

    case 'define' then
      P1 = 0
      P2 = 5
      P3 = 50
          
      model = scicos_model()
      model.sim = list('EX6', 4)
      model.out = [1]
      model.state = [0]
      model.dstate = []
      model.rpar = [P1; P2; P3]
      model.blocktype = 'c'
      model.dep_ut = [%f %t]
      
      exprs = string(model.rpar);
      gr_i = [
            'x=orig(1), y=orig(2), w=sz(1), h=sz(2)';
            'txt=[''CPU'';''Power generator'']';
            'xstringb(x + 0.25*w, y + 0.20*h, txt, 0.50*w, 0.60*h,
''fill'')';]
      x = standard_define([4 2], model, exprs, gr_i)

  end

endfunction

My computation code EX6.c

#include "scicos_block.h"
#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include "call_scilab.h"
#include "api_scilab.h" 
void EX6(scicos_block *blk, int flag)
{
    SendScilabJob("myMatrix=['sample','for the help']");//I want to call
scilabfoo function

    switch (flag)
    {
        case Initialization:
           blk->outptr[0][0] = blk->rpar[0] + blk->rpar[1] +blk->rpar[2];
            break;
        case Ending:
            break;
        case OutputUpdate:
            blk->outptr[0][0] = blk->rpar[0] + blk->rpar[1] +blk->rpar[2];
            break;
        default:
            break;
    }
}


--
View this message in context: http://mailinglists.scilab.org/Link-computational-function-written-in-Scilab-language-tp3697371p4024558.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list