[scilab-Users] Re: Link computational function written in Scilab language

Mike Page Mike at Page-One.Waitrose.com
Wed Jul 11 11:49:29 CEST 2012


Hi,

On my (Windows) system, LibScilab.lib is in C:\Program
Files\scilab-5.3.2\bin.  If you use a different OS, you'll have to find it
yourself.

I think you can use SendScilabJob to send any valid Scilab command to the
Scilab engine.  Before anything else, initialise the Scilab engine by
calling:

	if (StartScilab (NULL, NULL, 0) == FALSE)
	{
		printf ("Error : StartScilab\n");
	}

Then you can call like in your code:

     SendScilabJob("myMatrix=['sample','for the help']");//I want to call

This will create a string vector variable myMatrix in the Scilab workspace.

You might want to check the return code (int) from this to be sure there is
no error (== 0).  If you get an error (usually 999) from a particular
SendScilabJob message, it probably indicates that Scilab did not understand
that particular message.

After you've finished, shut down the Scilab engine by calling:

	if (TerminateScilab (NULL) == FALSE)
	{
		printf ("Error : TerminateScilab\n");
	}

To call your own function, first you need to send Scilab the function
definition, either by sending the function definition line-by-line or
sending "exec('myscilabfile');".  Note the use of single quotes within C.
Then you can send another string with your function call "r =
scilabfoo(x,y)".

Finally, I should say that I have only used this in Scilab, not Scicos, so
there may be differences ;-)

HTH,
Mike.



-----Original Message-----
From: hehiha [mailto:dungnguyenbk at gmail.com]
Sent: 11 July 2012 10:16
To: users at lists.scilab.org
Subject: [scilab-Users] Re: Link computational function written in
Scilab language


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.

--
To unsubscribe from this mailing-list, please send an empty mail to
users-unsubscribe at lists.scilab.org
To check the archives of this mailing list, see
http://mailinglists.scilab.org/



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2195 / Virus Database: 2437/5124 - Release Date: 07/10/12




More information about the users mailing list