~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/m2sci/help/en_US/sci_files.xml

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    *
12
12
    -->
13
13
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="sci_files">
14
 
  <refnamediv>
15
 
    <refname>sci_files</refname>
16
 
    <refpurpose>How to write conversion functions</refpurpose>
17
 
  </refnamediv>
18
 
  <refsection>
19
 
    <title>Description</title>
20
 
    <para>  
21
 
      To convert calls to Matlab functions, <literal>mfile2sci</literal> uses a function called
22
 
      <literal>sci_&lt;Matlab_function_name&gt;</literal>. All these functions are defined in <literal>sci_files</literal>
23
 
      in directory SCI/modules/m2sci/macros/sci_files/. The set of <literal>sci_files</literal> given in Scilab
24
 
      distribution does not allow to convert calls to all Matlab functions yet.
25
 
      However, a Scilab user can add <literal>sci_files</literal> (for Matlab functions or for user defined functions)
26
 
      to Scilab using the following tips. 
27
 
    </para>
28
 
    <para>
29
 
      In M2SCI, a function call is considered as a "tree" (it is also the case for the instructions
30
 
      of the file to convert), represented in Scilab by a <literal>tlist</literal> with following fields:
31
 
    </para>
32
 
    <itemizedlist>
33
 
      <listitem>
34
 
        <variablelist>
35
 
          <varlistentry>
36
 
            <term>name</term>
37
 
            <listitem>
38
 
              <para>Matlab function name</para>
39
 
            </listitem>
40
 
          </varlistentry>
41
 
          <varlistentry>
42
 
            <term>lhsnb</term>
43
 
            <listitem>
44
 
              <para>number of Matlab function output parameters</para>
45
 
            </listitem>
46
 
          </varlistentry>
47
 
          <varlistentry>
48
 
            <term>lhs</term>
49
 
            <listitem>
50
 
              <para>list of Matlab function output parameters</para>
51
 
            </listitem>
52
 
          </varlistentry>
53
 
          <varlistentry>
54
 
            <term>rhs</term>
55
 
            <listitem>
56
 
              <para>list of Matlab function input parameters</para>
57
 
            </listitem>
58
 
          </varlistentry>
59
 
        </variablelist>
60
 
      </listitem>
61
 
    </itemizedlist>
62
 
    <para>
63
 
      A <literal>sci_function</literal> has one input called <literal>tree</literal> which is also the output of the function.
64
 
      A <literal>sci_function</literal> has to convert this incoming "tree" so that it is compatible with Scilab
65
 
      by changing name, lhsnb, lhs and/or rhs. The other task that has to be done by this function
66
 
      is inference. Incoming tree contains inference data in its lhs that have to be updated with what
67
 
      can be infered for the outputs of this function. 
68
 
    </para>
69
 
    <para>
70
 
      Some useful functions have been written to help to create M2SCI tlists while writing this conversion function:
71
 
    </para>
72
 
    <itemizedlist>
73
 
      <listitem>
74
 
        <variablelist>
75
 
          <varlistentry>
76
 
            <term>Funcall</term>
77
 
            <listitem>
78
 
              <para>create a tree representing a function call</para>
79
 
            </listitem>
80
 
          </varlistentry>
81
 
          <varlistentry>
82
 
            <term>Operation</term>
83
 
            <listitem>
84
 
              <para>create a tree representing an operation</para>
85
 
            </listitem>
86
 
          </varlistentry>
87
 
          <varlistentry>
88
 
            <term>Variable</term>
89
 
            <listitem>
90
 
              <para>create a tree representing a variable</para>
91
 
            </listitem>
92
 
          </varlistentry>
93
 
          <varlistentry>
94
 
            <term>Cste</term>
95
 
            <listitem>
96
 
              <para>create a tree representing a constante value</para>
97
 
            </listitem>
98
 
          </varlistentry>
99
 
          <varlistentry>
100
 
            <term>Infer</term>
101
 
            <listitem>
102
 
              <para>create a tree representing inference data</para>
103
 
            </listitem>
104
 
          </varlistentry>
105
 
          <varlistentry>
106
 
            <term>Type</term>
107
 
            <listitem>
108
 
              <para>create a tree representing type for inference</para>
109
 
            </listitem>
110
 
          </varlistentry>
111
 
          <varlistentry>
112
 
            <term>Equal</term>
113
 
            <listitem>
114
 
              <para>create a tree representing an instruction</para>
115
 
            </listitem>
116
 
          </varlistentry>
117
 
        </variablelist>
118
 
      </listitem>
119
 
    </itemizedlist>
120
 
    <para>
121
 
      Some other functions have been designed to get properties of operands/inputs. Considering A is tlist used in macro tree, you can use the following functions:
122
 
    </para>
123
 
    <informaltable border="1">
124
 
      <tr>
125
 
        <td>Function</td>
126
 
        <td>
127
 
          returns <literal>%T</literal> if...
128
 
        </td>
129
 
      </tr>
130
 
      <tr>
131
 
        <td>
132
 
          <literal>is_empty(A)</literal>
133
 
        </td>
134
 
        <td>all dimensions of A are 0</td>
135
 
      </tr>
136
 
      <tr>
137
 
        <td>
138
 
          <literal>not_empty(A)</literal>
139
 
        </td>
140
 
        <td>all dimensions of A are known and at least one dimension of A is not 0</td>
141
 
      </tr>
142
 
      <tr>
143
 
        <td>
144
 
          <literal>is_a_scalar(A)</literal>
145
 
        </td>
146
 
        <td>all dimensions of A are 1</td>
147
 
      </tr>
148
 
      <tr>
149
 
        <td>
150
 
          <literal>not_a_scalar(A)</literal>
151
 
        </td>
152
 
        <td>all dimensions of A are known and at least one dimension of A is not 1</td>
153
 
      </tr>
154
 
      <tr>
155
 
        <td>
156
 
          <literal>is_a_vector(A)</literal>
157
 
        </td>
158
 
        <td>all dimensions of A are known and all dimensions of A but one are equal to 1</td>
159
 
      </tr>
160
 
      <tr>
161
 
        <td>
162
 
          <literal>not_a_vector(A)</literal>
163
 
        </td>
164
 
        <td>all dimensions of A are known and at least two dimensions of A are greater than one</td>
165
 
      </tr>
166
 
      <tr>
167
 
        <td>
168
 
          <literal>is_real(A)</literal>
169
 
        </td>
170
 
        <td>A is real</td>
171
 
      </tr>
172
 
      <tr>
173
 
        <td>
174
 
          <literal>is_complex(A)</literal>
175
 
        </td>
176
 
        <td>A is complex</td>
177
 
      </tr>
178
 
      <tr>
179
 
        <td>
180
 
          <literal>isdefinedvar(A)</literal>
181
 
        </td>
182
 
        <td>A is a variable already created in M-file currently converted</td>
183
 
      </tr>
184
 
      <tr>
185
 
        <td>
186
 
          <literal>allunknown(A)</literal>
187
 
        </td>
188
 
        <td>all dimensions of A are unknown</td>
189
 
      </tr>
190
 
    </informaltable>
191
 
    <para>
192
 
      Some other functions have been written for specific needs while writing conversion files:
193
 
    </para>
194
 
    <itemizedlist>
195
 
      <listitem>
196
 
        <variablelist>
197
 
          <varlistentry>
198
 
            <term>first_non_singleton</term>
199
 
            <listitem>
200
 
              <para>
201
 
                is an equivalent to <link linkend="firstnonsingleton">firstnonsingleton</link> for an M2SCI tlist. Calling sequence: <literal>dim = first_non_singleton(A)</literal>
202
 
              </para>
203
 
            </listitem>
204
 
          </varlistentry>
205
 
          <varlistentry>
206
 
            <term>gettempvar</term>
207
 
            <listitem>
208
 
              <para>
209
 
                generates a temporary variable having a name which does not already exist. Calling sequence:<literal> v = gettempvar()</literal>
210
 
              </para>
211
 
            </listitem>
212
 
          </varlistentry>
213
 
          <varlistentry>
214
 
            <term>insert</term>
215
 
            <listitem>
216
 
              <para>
217
 
                allows to insert instructions. Calling sequence:<literal> insert(Equal(...),opt)</literal> with <literal>opt~=1</literal>  to insert before current instruction and <literal> opt=1</literal>  to insert after it.
218
 
              </para>
219
 
            </listitem>
220
 
          </varlistentry>
221
 
          <varlistentry>
222
 
            <term>getoperands</term>
223
 
            <listitem>
224
 
              <para>
225
 
                can be used to get each operand as a variable. Calling sequence: <literal>[A,B] = getoperands(operation_tlist)</literal>
226
 
              </para>
227
 
            </listitem>
228
 
          </varlistentry>
229
 
          <varlistentry>
230
 
            <term>getrhs</term>
231
 
            <listitem>
232
 
              <para>
233
 
                can be used to get each parameter as a variable. Calling sequence: <literal>[A,...] = getrhs(funcall_tlist)</literal>
234
 
              </para>
235
 
            </listitem>
236
 
          </varlistentry>
237
 
          <varlistentry>
238
 
            <term>convert2double</term>
239
 
            <listitem>
240
 
              <para>
241
 
                change type of input when this type is not implemented for a particular function is Scilab. Calling sequence:<literal> A = convert2double(A)</literal>
242
 
              </para>
243
 
            </listitem>
244
 
          </varlistentry>
245
 
        </variablelist>
246
 
      </listitem>
247
 
    </itemizedlist>
248
 
    <para>
249
 
      To have more information about how to write such files, refer to directory
250
 
      SCI/modules/m2sci/macros/sci_files/ which gives many examples from very simple ones
251
 
      (e.g. sci_abs.sci) to very complex ones (e.g. sci_zeros.sci).
252
 
    </para>
253
 
  </refsection>
254
 
  <refsection role="see also">
255
 
    <title>See Also</title>
256
 
    <simplelist type="inline">
257
 
      <member>
258
 
        <link linkend="m2scideclare">m2scideclare</link>
259
 
      </member>
260
 
      <member>
261
 
        <link linkend="Funcall">Funcall</link>
262
 
      </member>
263
 
      <member>
264
 
        <link linkend="Operation">Operation</link>
265
 
      </member>
266
 
      <member>
267
 
        <link linkend="Variable">Variable</link>
268
 
      </member>
269
 
      <member>
270
 
        <link linkend="Cste">Cste</link>
271
 
      </member>
272
 
      <member>
273
 
        <link linkend="Infer">Infer</link>
274
 
      </member>
275
 
      <member>
276
 
        <link linkend="Type">Type</link>
277
 
      </member>
278
 
      <member>
279
 
        <link linkend="Equal">Equal</link>
280
 
      </member>
281
 
    </simplelist>
282
 
  </refsection>
 
14
    <refnamediv>
 
15
        <refname>sci_files</refname>
 
16
        <refpurpose>How to write conversion functions</refpurpose>
 
17
    </refnamediv>
 
18
    <refsection>
 
19
        <title>Description</title>
 
20
        <para>  
 
21
            To convert calls to Matlab functions, <literal>mfile2sci</literal> uses a function called
 
22
            <literal>sci_&lt;Matlab_function_name&gt;</literal>. All these functions are defined in <literal>sci_files</literal>
 
23
            in directory SCI/modules/m2sci/macros/sci_files/. The set of <literal>sci_files</literal> given in Scilab
 
24
            distribution does not allow to convert calls to all Matlab functions yet.
 
25
            However, a Scilab user can add <literal>sci_files</literal> (for Matlab functions or for user defined functions)
 
26
            to Scilab using the following tips. 
 
27
        </para>
 
28
        <para>
 
29
            In M2SCI, a function call is considered as a "tree" (it is also the case for the instructions
 
30
            of the file to convert), represented in Scilab by a <literal>tlist</literal> with following fields:
 
31
        </para>
 
32
        <itemizedlist>
 
33
            <listitem>
 
34
                <variablelist>
 
35
                    <varlistentry>
 
36
                        <term>name</term>
 
37
                        <listitem>
 
38
                            <para>Matlab function name</para>
 
39
                        </listitem>
 
40
                    </varlistentry>
 
41
                    <varlistentry>
 
42
                        <term>lhsnb</term>
 
43
                        <listitem>
 
44
                            <para>number of Matlab function output parameters</para>
 
45
                        </listitem>
 
46
                    </varlistentry>
 
47
                    <varlistentry>
 
48
                        <term>lhs</term>
 
49
                        <listitem>
 
50
                            <para>list of Matlab function output parameters</para>
 
51
                        </listitem>
 
52
                    </varlistentry>
 
53
                    <varlistentry>
 
54
                        <term>rhs</term>
 
55
                        <listitem>
 
56
                            <para>list of Matlab function input parameters</para>
 
57
                        </listitem>
 
58
                    </varlistentry>
 
59
                </variablelist>
 
60
            </listitem>
 
61
        </itemizedlist>
 
62
        <para>
 
63
            A <literal>sci_function</literal> has one input called <literal>tree</literal> which is also the output of the function.
 
64
            A <literal>sci_function</literal> has to convert this incoming "tree" so that it is compatible with Scilab
 
65
            by changing name, lhsnb, lhs and/or rhs. The other task that has to be done by this function
 
66
            is inference. Incoming tree contains inference data in its lhs that have to be updated with what
 
67
            can be infered for the outputs of this function. 
 
68
        </para>
 
69
        <para>
 
70
            Some useful functions have been written to help to create M2SCI tlists while writing this conversion function:
 
71
        </para>
 
72
        <itemizedlist>
 
73
            <listitem>
 
74
                <variablelist>
 
75
                    <varlistentry>
 
76
                        <term>Funcall</term>
 
77
                        <listitem>
 
78
                            <para>create a tree representing a function call</para>
 
79
                        </listitem>
 
80
                    </varlistentry>
 
81
                    <varlistentry>
 
82
                        <term>Operation</term>
 
83
                        <listitem>
 
84
                            <para>create a tree representing an operation</para>
 
85
                        </listitem>
 
86
                    </varlistentry>
 
87
                    <varlistentry>
 
88
                        <term>Variable</term>
 
89
                        <listitem>
 
90
                            <para>create a tree representing a variable</para>
 
91
                        </listitem>
 
92
                    </varlistentry>
 
93
                    <varlistentry>
 
94
                        <term>Cste</term>
 
95
                        <listitem>
 
96
                            <para>create a tree representing a constante value</para>
 
97
                        </listitem>
 
98
                    </varlistentry>
 
99
                    <varlistentry>
 
100
                        <term>Infer</term>
 
101
                        <listitem>
 
102
                            <para>create a tree representing inference data</para>
 
103
                        </listitem>
 
104
                    </varlistentry>
 
105
                    <varlistentry>
 
106
                        <term>Type</term>
 
107
                        <listitem>
 
108
                            <para>create a tree representing type for inference</para>
 
109
                        </listitem>
 
110
                    </varlistentry>
 
111
                    <varlistentry>
 
112
                        <term>Equal</term>
 
113
                        <listitem>
 
114
                            <para>create a tree representing an instruction</para>
 
115
                        </listitem>
 
116
                    </varlistentry>
 
117
                </variablelist>
 
118
            </listitem>
 
119
        </itemizedlist>
 
120
        <para>
 
121
            Some other functions have been designed to get properties of operands/inputs. Considering A is tlist used in macro tree, you can use the following functions:
 
122
        </para>
 
123
        <informaltable border="1">
 
124
            <tr>
 
125
                <td>Function</td>
 
126
                <td>
 
127
                    returns <literal>%T</literal> if...
 
128
                </td>
 
129
            </tr>
 
130
            <tr>
 
131
                <td>
 
132
                    <literal>is_empty(A)</literal>
 
133
                </td>
 
134
                <td>all dimensions of A are 0</td>
 
135
            </tr>
 
136
            <tr>
 
137
                <td>
 
138
                    <literal>not_empty(A)</literal>
 
139
                </td>
 
140
                <td>all dimensions of A are known and at least one dimension of A is not 0</td>
 
141
            </tr>
 
142
            <tr>
 
143
                <td>
 
144
                    <literal>is_a_scalar(A)</literal>
 
145
                </td>
 
146
                <td>all dimensions of A are 1</td>
 
147
            </tr>
 
148
            <tr>
 
149
                <td>
 
150
                    <literal>not_a_scalar(A)</literal>
 
151
                </td>
 
152
                <td>all dimensions of A are known and at least one dimension of A is not 1</td>
 
153
            </tr>
 
154
            <tr>
 
155
                <td>
 
156
                    <literal>is_a_vector(A)</literal>
 
157
                </td>
 
158
                <td>all dimensions of A are known and all dimensions of A but one are equal to 1</td>
 
159
            </tr>
 
160
            <tr>
 
161
                <td>
 
162
                    <literal>not_a_vector(A)</literal>
 
163
                </td>
 
164
                <td>all dimensions of A are known and at least two dimensions of A are greater than one</td>
 
165
            </tr>
 
166
            <tr>
 
167
                <td>
 
168
                    <literal>is_real(A)</literal>
 
169
                </td>
 
170
                <td>A is real</td>
 
171
            </tr>
 
172
            <tr>
 
173
                <td>
 
174
                    <literal>is_complex(A)</literal>
 
175
                </td>
 
176
                <td>A is complex</td>
 
177
            </tr>
 
178
            <tr>
 
179
                <td>
 
180
                    <literal>isdefinedvar(A)</literal>
 
181
                </td>
 
182
                <td>A is a variable already created in M-file currently converted</td>
 
183
            </tr>
 
184
            <tr>
 
185
                <td>
 
186
                    <literal>allunknown(A)</literal>
 
187
                </td>
 
188
                <td>all dimensions of A are unknown</td>
 
189
            </tr>
 
190
        </informaltable>
 
191
        <para>
 
192
            Some other functions have been written for specific needs while writing conversion files:
 
193
        </para>
 
194
        <itemizedlist>
 
195
            <listitem>
 
196
                <variablelist>
 
197
                    <varlistentry>
 
198
                        <term>first_non_singleton</term>
 
199
                        <listitem>
 
200
                            <para>
 
201
                                is an equivalent to <link linkend="firstnonsingleton">firstnonsingleton</link> for an M2SCI tlist. Calling sequence: <literal>dim = first_non_singleton(A)</literal>
 
202
                            </para>
 
203
                        </listitem>
 
204
                    </varlistentry>
 
205
                    <varlistentry>
 
206
                        <term>gettempvar</term>
 
207
                        <listitem>
 
208
                            <para>
 
209
                                generates a temporary variable having a name which does not already exist. Calling sequence:<literal> v = gettempvar()</literal>
 
210
                            </para>
 
211
                        </listitem>
 
212
                    </varlistentry>
 
213
                    <varlistentry>
 
214
                        <term>insert</term>
 
215
                        <listitem>
 
216
                            <para>
 
217
                                allows to insert instructions. Calling sequence:<literal> insert(Equal(...),opt)</literal> with <literal>opt~=1</literal>  to insert before current instruction and <literal> opt=1</literal>  to insert after it.
 
218
                            </para>
 
219
                        </listitem>
 
220
                    </varlistentry>
 
221
                    <varlistentry>
 
222
                        <term>getoperands</term>
 
223
                        <listitem>
 
224
                            <para>
 
225
                                can be used to get each operand as a variable. Calling sequence: <literal>[A,B] = getoperands(operation_tlist)</literal>
 
226
                            </para>
 
227
                        </listitem>
 
228
                    </varlistentry>
 
229
                    <varlistentry>
 
230
                        <term>getrhs</term>
 
231
                        <listitem>
 
232
                            <para>
 
233
                                can be used to get each parameter as a variable. Calling sequence: <literal>[A,...] = getrhs(funcall_tlist)</literal>
 
234
                            </para>
 
235
                        </listitem>
 
236
                    </varlistentry>
 
237
                    <varlistentry>
 
238
                        <term>convert2double</term>
 
239
                        <listitem>
 
240
                            <para>
 
241
                                change type of input when this type is not implemented for a particular function is Scilab. Calling sequence:<literal> A = convert2double(A)</literal>
 
242
                            </para>
 
243
                        </listitem>
 
244
                    </varlistentry>
 
245
                </variablelist>
 
246
            </listitem>
 
247
        </itemizedlist>
 
248
        <para>
 
249
            To have more information about how to write such files, refer to directory
 
250
            SCI/modules/m2sci/macros/sci_files/ which gives many examples from very simple ones
 
251
            (e.g. sci_abs.sci) to very complex ones (e.g. sci_zeros.sci).
 
252
        </para>
 
253
    </refsection>
 
254
    <refsection role="see also">
 
255
        <title>See Also</title>
 
256
        <simplelist type="inline">
 
257
            <member>
 
258
                <link linkend="m2scideclare">m2scideclare</link>
 
259
            </member>
 
260
            <member>
 
261
                <link linkend="Funcall">Funcall</link>
 
262
            </member>
 
263
            <member>
 
264
                <link linkend="Operation">Operation</link>
 
265
            </member>
 
266
            <member>
 
267
                <link linkend="Variable">Variable</link>
 
268
            </member>
 
269
            <member>
 
270
                <link linkend="Cste">Cste</link>
 
271
            </member>
 
272
            <member>
 
273
                <link linkend="Infer">Infer</link>
 
274
            </member>
 
275
            <member>
 
276
                <link linkend="Type">Type</link>
 
277
            </member>
 
278
            <member>
 
279
                <link linkend="Equal">Equal</link>
 
280
            </member>
 
281
        </simplelist>
 
282
    </refsection>
283
283
</refentry>