summaryrefslogtreecommitdiff
path: root/cesar/cp2/pwl/doc/scilab/convertc.sce
blob: 0c202fe5ce84c9f2204178a976aa4a5d31461442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPiDCOM Technologies.
// Nélio Laranjeiro
// 16-05-2008
// Cesar project.

// Convert an array of values to a C array.

// @param  file_name  the file name to write the data in. The file shall be a
// c file.
// @param  array_name  the array name.
// @param  array  the array to write.
function convertc_array (file_name, array_name, array)

nb_points = length(array);
define_name = file_name + "_" + array_name;

// Provide an array for the C unit test.
result_file = file ('open', file_name, 'unknown');
 fprintf (result_file, "#ifndef %s", define_name);
 fprintf (result_file, "#define %s", define_name);
 fprintf (result_file, "/* File generated by scilab */");
 fprintf (result_file, "");
 fprintf (result_file, "u8 %s [%d] = {", array_name, nb_points);
 for i = 1:nb_points - 1
  fprintf (result_file, " %d, ", array(i));
 end

// Write the last value.
fprintf (result_file, "%d };", array(nb_points));
fprintf (result_file, "uint %s = %d;", array_name + '_length', nb_points);

fprintf (result_file, "#endif /* %s */", define_name);
file ('close', result_file);

endfunction