Blog: Two and half implementations of a scilab wrapper without any compilation: scilab_with_OpenTURNSPythonFunction.py

File scilab_with_OpenTURNSPythonFunction.py, 809 bytes (added by regis.lebrun@…, 5 years ago)

Scilab wrapping using the OpenTURNSPythonFunction

Line 
1from openturns import *
2import os
3
4class otfunc(OpenTURNSPythonFunction):
5     
6    def __init__(self, inputDimension, outputDimension):
7      OpenTURNSPythonFunction.__init__(self, inputDimension, outputDimension)
8
9    def _exec(self, X):
10          f = file("input.data", "w")
11          f.write("x1 = " + str(X[0]) + "\n")
12          f.write("x2 = " + str(X[1]) + "\n")
13          f.close()
14          rc = os.system("scilab -nb -nwni -f code.sce")
15          f = file("result.data", "r")
16          Y = [float(f.readline().split(" ")[2])]
17          f.close()
18          return Y
19
20model = NumericalMathFunction( otfunc(2, 1) )
21inP = [1.0, 2.0]
22outP = model(inP)
23print "model(", inP, ")=", outP
24inS = Normal(2).getNumericalSample(100)
25Log.SetColor(Log.INFO, TTY.CYANFG)
26outS = model(inS)
27print outS.computeMean()