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

File scilab_with_generic_wrapper.py, 1.8 KB (added by regis.lebrun@…, 5 years ago)

Scilab wrapping using the generic wrapper

Line 
1from openturns import *
2
3# Needed to solve ticket #473
4WrapperDataVariableType.IN = 0
5WrapperDataVariableType.OUT = 1
6WrapperDataFileType.IN = 0
7WrapperDataFileType.OUT = 1
8
9# Variables
10vars = ({ "id_" : "x1",
11          "type_" : WrapperDataVariableType.IN,
12          "regexp_" : "^\S*x1\S*=\S*\R\S*$",
13          "format_" : "x1=%.20e"  },
14       
15        { "id_" : "x2",
16          "type_" : WrapperDataVariableType.IN,
17          "regexp_" : "^\S*x2\S*=\S*\R\S*$",
18          "format_" : "x2=%.20e"  },
19       
20        { "id_" : "y",
21          "type_" : WrapperDataVariableType.OUT,
22          "regexp_" : "^\S*y\S*=\S*(\R)\S*$" },
23        )
24
25# Files
26files = ({ "id_" : "infile",
27           "type_" : WrapperDataFileType.IN,
28           "path_" : "input.data",
29           "subst_" : "x1,x2"  },
30         
31         { "id_" : "script",
32           "type_" : WrapperDataFileType.IN,
33           "path_" : "code.sce" },
34         
35         { "id_" : "outfile",
36           "type_" : WrapperDataFileType.OUT,
37           "path_" : "result.data",
38           "subst_" : "y"    },
39         )
40
41# Parameters
42params = { "command_" : "scilab -nb -nwni -f code.sce",
43           "userPrefix_" : "GenericWrapperTest",
44           }
45
46# Framework
47framework = { "studyid_" : 1,
48              "studycase_" : "WrapperExample",
49              "componentname_" : "SimpleSum"
50              }
51
52ResourceMap.Set("output-files-timeout", "0")
53ResourceMap.Set("computation-progression-update-interval", "1")
54Log.Show(Log.INFO)
55scilabWrapper = makeWrapper( vars, files, params, framework )
56
57# Export the wrapper in XML if needed
58# scilabWrapper.writeFile( "code.xml" )
59
60model = NumericalMathFunction( scilabWrapper )
61inP = [1.0, 2.0]
62outP = model(inP)
63print "model(", inP, ")=", outP
64inS = Normal(2).getNumericalSample(100)
65Log.SetColor(Log.INFO, TTY.CYANFG)
66outS = model(inS)
67print outS.computeMean()