File size: 8,495 Bytes
39e01c4 | 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | // Xcos
//
// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See the file ../license.txt
//
function [x,y,typ] = READC_f(job,arg1,arg2)
x=[];
y=[];
typ=[];
select job
case "set" then
x = arg1;
model = x.model;
graphics = arg1.graphics;
exprs = graphics.exprs
out = model.out
dstate = model.dstate
ipar = model.ipar
imask = 9+ipar(1)
tmask = ipar(imask)
lunit = dstate(3)
fname = exprs(3)
frmt = exprs(4)
while %t do
[ok,tmask1,outmask,fname1,frmt1,M,N,offset,swap,exprs] = scicos_getvalue(..
[msprintf(gettext("Set %s block parameters"), "READC_f" );
" ";
gettext("Read from C binary file")], ..
_(["Time Record Selection";
"Outputs Record Selection";
"Input File Name";
"Input Format";
"Record Size";
"Buffer Size"; ..
"Initial Record Index";
"Swap Mode (0:No, 1:Yes)"]), ..
list("vec", -1, "vec", -1, "str", 1, "str", 1, "vec", 1, "vec", 1,"vec", 1, "vec", 1), exprs);
if ~ok then
break
end //user cancel modification
fname1 = pathconvert(stripblanks(fname1), %f, %t)
frmt1 = stripblanks(frmt1)
fmts = [ "s","l","d","f","c","us","ul","uc","ull","uls","ubl","ubs","dl","fl","ll","sl","db","fb","lb","sb"];
nout = size(outmask,"*")
if prod(size( tmask1 )) > 1 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Time Record Selection")), ..
gettext("Must be a scalar or an empty matrix."))
elseif and(frmt1 <> fmts) then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Input Format"), frmt1), ..
gettext("Valid formats are: " + strcat(fmts,", ")));
elseif alreadyran & fname1 <> fname then
block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running"), gettext("Input File Name")), ..
gettext("End current simulation first."));
elseif N <> ipar(6) & alreadyran then
block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Buffer Size")), ..
gettext("End current simulation first"));
elseif alreadyran & size(tmask1) <> size(tmask) then
block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Time Record Selection")), ..
gettext("End current simulation first."));
elseif fname1 == "" then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Input File Name")), ..
gettext("You must provide a file name."));
elseif M < 1 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Record Size"), M), ..
gettext("Strictly positive integer expected."));
elseif tmask1 ~= [] & (tmask1 < 1 | tmask1 > M) then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Time Record Selection"), tmask1), ..
msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]"));
elseif nout == 0 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Outputs Record Selection"), nout), ..
gettext("Strictly positive integer expected."));
elseif nout > M then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Outputs Record Selection"), nout), ..
msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]"));
elseif max(outmask) > M | min(outmask) < 1 then
block_parameter_error(msprintf(gettext("Wrong value for indexes in ''%s'' parameter: %s."), gettext("Outputs Record Selection"), strcat(string(outmask(:))," ")), ..
msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]"));
elseif N < 1 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), ..
gettext("Strictly positive integer expected."));
elseif swap <> 0 & swap <> 1 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Swap Mode"), swap), ..
msprintf(gettext("Must be in the interval %s."), "[0, 1]"));
elseif offset < 1 then
block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Initial Record Index"), offset), ..
gettext("Strictly positive integer expected."));
else
if tmask1 == [] then
ievt = 0;
tmask1 = 0;
outpt = [];
else
ievt = 1;
outpt = 1;
end
out = size(outmask,"*")
[model,graphics,ok] = check_io(model,graphics,[],out,1,outpt)
frmt1 = part(frmt1,1:3);
if ok then
if ievt == 0 then
model.firing = -1
else
model.firing = 0
end
ipar = [ ...
length(ascii(fname1)); ...
ascii(frmt1)'; ...
ievt; ...
N; ...
M; ...
swap; ...
offset; ...
ascii(fname1)'; ...
tmask1; ...
outmask(:) ...
];
if prod(size(dstate)) <> (N*M) + 3 then
dstate = [-1; -1; lunit; zeros(N*M, 1)]
end
model.dstate = dstate;
model.ipar = ipar
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model
break
end
end
end
case "define" then
frmt = "d "
fname = "foo"
lunit = 0
N = 20;
M = 1
rpar = []
tmask = 0
swap = 0
offset = 1
outmask = 1
ievt = 0
nout = size(outmask,"*")
ipar = [ ...
length(ascii(fname)); ascii(frmt)'; ievt; N; M; ...
swap;offset; ascii(fname)'; tmask; outmask ...
];
model = scicos_model()
model.sim = list("readc",2)
model.out = nout
model.evtin = 1
model.evtout = []
model.dstate = [1; 1; lunit; zeros(N*M,1)]
model.ipar = [ ...
length(ascii(fname)); ascii(frmt)'; ievt; N; M; ...
swap; offset;ascii(fname)'; ...
tmask; outmask ...
];
model.blocktype = "d"
model.firing = -1
model.dep_ut = [%f %f]
exprs = [ ...
"[]"; sci2exp(outmask); fname; frmt; string(M); ...
string(N); string(offset);string(swap) ...
];
gr_i = [];
x = standard_define([4 2],model,exprs,gr_i)
end
endfunction
|