/
perform_scilab_conversion.m
104 lines (87 loc) · 2.16 KB
/
perform_scilab_conversion.m
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function perform_scilab_conversion(name, outdir, toolbox_dir)
% perform_scilab_conversion - convert a matlab file to scilab
%
% perform_scilab_conversion(name);
%
% If name is empty, process all the files.
%
% Copyright (c) 2008 Gabriel Peyre
if nargin<2
outdir = '../scilab/';
end
if nargin<3
toolbox_dir = '../matlab/';
end
if nargin<1 || isempty(name)
% back processing
list_ext = {'coding_' 'introduction_' 'image_' 'audio_' 'wavelet_' 'sparsity_' 'cs_' ...
'denoising_' 'inverse_' 'graphics_' 'multidim_' 'meshproc_' 'meshdeform_' ...
'meshwav_' 'variational_' 'fastmarching_'};
a = dir('*_*.m');
for i=1:length(a)
name = a(i).name;
for k=1:length(list_ext)
if not(isempty( findstr(name, list_ext{k}) ))
disp(['---> Translating ' name ' ...']);
perform_scilab_conversion(name(1:end-2));
end
end
end
return;
end
fid = fopen([name '.m'], 'rt');
fidout = fopen([outdir name '.sce'], 'wt');
if fid<0
error(['Cannot open ' name '.m.']);
end
str1 = {'%' '\' 'getd(''' };
str2 = {'//' '\\' ['getd(''' toolbox_dir] };
while true
s = fgets(fid);
if s<0
break;
end
% remove comments and stufs
for i=1:length(str1)
s = strrep(s,str1{i},str2{i});
end
makeoutput = 1;
if length(s)>5 && strcmp(s(1:6), 'getd =')
makeoutput = 0;
end
if length(s)>28 && strcmp(s(1:28), 'perform_toolbox_installation')
process_header(fidout, s);
makeoutput = 0;
end
% write output
if makeoutput
fprintf(fidout, s);
end
end
fclose(fid);
fclose(fidout);
%%
function process_header(fidout, s)
tbx = {};
if findstr(s, 'signal')
tbx{end+1} = 'signal';
end
if findstr(s, 'general')
tbx{end+1} = 'general';
end
if findstr(s, 'graph')
tbx{end+1} = 'graph';
end
if findstr(s, 'wavelet_meshes')
tbx{end+1} = 'wavelet_meshes';
end
if findstr(s, 'additional')
tbx{end+1} = 'additional';
end
for i=1:length(tbx)
output_line(fidout, ['getd(''toolbox_' tbx{i} '/'');\n']);
end
%%
function output_line(fid,s)
s = strrep(s,'%','%%');
fprintf(fid, s);