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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
// Copyright (C) ???? - INRIA - Serge STEER
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function count = mtlb_fprintf(varargin)
// Emulation function for fprintf() Matlab function
[lhs,rhs]=argn()
count=0
// No fid given: mtlb_fprintf(fmt,...)
// Output is the screen
if size(varargin)==1 & type(varargin(1))==10 then
mprintf("%s \n",varargin(1))
count=length(varargin(1))
elseif type(varargin(1))==10 then
fmt=varargin(1)
nfmt=size(strindex(fmt,"%"),"*")
nv=size(varargin)-1
if nv==1 then
a=varargin(2)
na=size(a,"*")
// If more values than formats
mult=max(na/nfmt,1)
fmt=strcat(fmt(ones(1,mult))) // duplicate format
l=list()
A=a
for k=1:size(a,"*")
l($+1)=A(k)
end
mprintf(fmt,l(:))
count=size(a,"*")
elseif nv==0 then
error(msprintf(gettext("%s: %s is not implemented.\n"),"mtlb_fprintf","mprintf("+fmt+")"));
else
sz=[]
for k=1:nv
sz=[sz size(varargin(k+1),1)]
end
// Size of args is verified because Scilab mprintf function
// does not work if args have more than one row
if and(sz==1) then // All args have only one row
mult=max(nv/nfmt,1)
fmt=strcat(fmt(ones(1,mult))) // duplicate format
mprintf(fmt,varargin(2:$))
count=size(sz,"*")
else
error(msprintf(gettext("%s: %s Scilab function does not work with more than one row variables.\n"),"mtlb_fprintf","mprintf"))
end
end
// mtlb_fprintf(fid,fmt,...)
else
fid=varargin(1)
fmt=varargin(2)
// count % in fmt
nfmt=size(strindex(fmt,"%"),"*")
nv=size(varargin)-2
if nv==1 then
a=varargin(3)
na=size(a,"*")
mult=max(na/nfmt,1)
fmt=strcat(fmt(ones(1,mult))) // duplicate format
l=list()
for k=1:size(a,"*")
l(k)=a(k)
end
if or(fid==[1 2]) then
mprintf(fmt,l(:))
count=size(a,"*")
else
mfprintf(fid,fmt,l(:))
count=size(a,"*")
end
elseif nv==0 & nfmt==0 & type(varargin(2))==10
mfprintf(fid,"%s",varargin(2))
count=length(varargin(2))
elseif nv==0 then
if or(fid==[1 2]) then
error(msprintf(gettext("%s: %s is not implemented.\n"),"mtlb_fprintf", "mprintf(format)"))
else
error(msprintf(gettext("%s: %s is not implemented.\n"),"mtlb_fprintf","mfprintf(fid,format)"))
end
else
sz=[]
for k=1:nv
sz=[sz size(varargin(k+2),1)]
end
if and(sz==1) then
mult=max(nv/nfmt,1)
fmt=strcat(fmt(ones(1,mult))) // duplicate format
if or(fid==[1 2]) then
mprintf(fmt,varargin(3:$))
count=size(sz,"*")
else
mfprintf(fid,fmt,varargin(3:$))
count=size(sz,"*")
end
else
if or(fid==[1 2]) then
error(msprintf(gettext("%s: %s Scilab function does not work with more than one row variables.\n"),"mtlb_fprintf", "mprintf"))
else
fprintfMat(fid,varargin(3:$),fmt)
for k=1:nv
count=count+size(varargin(k+2),"*")
end
end
end
end
end
endfunction
|