Link computational function written in Scilab language

classic Classic list List threaded Threaded
6 messages Options
melmak melmak
Reply | Threaded
Open this post in threaded view
|

Link computational function written in Scilab language

I have computational function written in Scilab language. How can I link it to Scilab? For C comptational it is ilib_for_link but what about Scilab comp function?
Adrien Vogt-Schilb Adrien Vogt-Schilb
Reply | Threaded
Open this post in threaded view
|

Re: Link computational function written in Scilab language

On 29/01/2012 13:10, melmak wrote:
I have computational function written in Scilab language. How can I link it
to Scilab? For C comptational it is ilib_for_link but what about Scilab comp
function?

--
View this message in context: http://mailinglists.scilab.org/Link-computational-function-written-in-Scilab-language-tp3697371p3697371.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
[hidden email]
To check the archives of this mailing list, see
http://mailinglists.scilab.org/
hi

you just have to move the function definition in a new file that you could call myfuntions.sci, then execute it with exec
you can have a look at the getd function too

tru this from the scilab console

help exec

help getd

(i would not recommend to use comp)

(you are not going to make your scilab written function execute faster by "compiling them")

hope it helps
hehiha hehiha
Reply | Threaded
Open this post in threaded view
|

Re: Link computational function written in Scilab language

I implement my module.
My computation written by c language.
In some case. c computation will call interface written by scilab.
Could you tell me how to call interface written by scilab form c computation.
Mike Page Mike Page
Reply | Threaded
Open this post in threaded view
|

Re: Link computational function written in Scilab language

Hi,

If you want to call Scilab functions from within C code, you can use
SendScilabJob.  This is described in the help system.  Don't forget to
include the necessary files in your C files:

#include "call_scilab.h"
#include "api_scilab.h"

And also add LibScilab.lib (assuming Windows) to your linker.


If you want to do it the other way round (call a module written in C from
within Scilab) you need to build the C code into a DLL (again Windows) and
link that into Scilab using:

link ("Path\filename.dll", functions, "c");

where functions is a string vector of entry point names.  For more help see
"link" in the Scilab help.

There are other ways to do this - see help for more info.

HTH,
Mike.



-----Original Message-----
From: hehiha [mailto:[hidden email]]
Sent: 11 July 2012 05:35
To: [hidden email]
Subject: [scilab-Users] Re: Link computational function written in
Scilab language


I implement my module.
My computation written by c language.
In some case. c computation will call interface written by scilab.
Could you tell me how to call interface written by scilab form c
computation.

--
View this message in context:
http://mailinglists.scilab.org/Link-computational-function-written-in-Scilab
-language-tp3697371p4024554.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
[hidden email]
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/5123 - Release Date: 07/10/12


--
To unsubscribe from this mailing-list, please send an empty mail to
[hidden email]
To check the archives of this mailing list, see
http://mailinglists.scilab.org/

hehiha hehiha
Reply | Threaded
Open this post in threaded view
|

Re: Link computational function written in Scilab language

This post was updated on .
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;
      while %t do
        [ok, a, b, c, exprs] = getvalue(..
                                                  'Set Parameters',..
                                                  ['money';..
                                                  'time';..
                                                  'total'],..
                                                  list('vec', 1, 'vec', 1, 'vec', 1),..
                                                  exprs)
                                                 

        if ~ok then break, end
         
        model.rpar = [a; b; c]
        graphics.exprs = exprs
        x.graphics = graphics
        x.model = model
        break
      end

    case 'define' then
      a = 0
      b = 5
      c = 50
         
      model = scicos_model()
      model.sim = list('EX6', 4)
      model.out = [1]
      model.state = [0]
      model.dstate = []
      model.rpar = [a; b; c]
      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;
    }
}
Mike Page Mike Page
Reply | Threaded
Open this post in threaded view
|

Re: Link computational function written in Scilab language

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:[hidden email]]
Sent: 11 July 2012 10:16
To: [hidden email]
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
[hidden email]
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


--
To unsubscribe from this mailing-list, please send an empty mail to
[hidden email]
To check the archives of this mailing list, see
http://mailinglists.scilab.org/