The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Pass Strings to Level2 MS Function
Replies: 1   Last Post: Mar 18, 2013 9:32 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 83
Registered: 6/22/12
Pass Strings to Level2 MS Function
Posted: Mar 18, 2013 9:23 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


I have a Constant block with the following value: uint8('120percent.txt'). I pass this value as an input to my Level2 MS Function. I've set the associated Inputport.Dimensions to be dynamic i.e. adapting to the size of the string.

At the Outputs method, I made a local variable that reverses the InputPort.Data back to its string value using the following command:
FileName = char(block.InputPort(1).Data);

When I run my file, I receive an error saying: "the file cannot be found or permission denid," and it points out at the line code which says:
text_lines = length(dataread('file', FileName, '%s', 'delimiter', '\n'));

Although I have, in this Level2 Function, used FileName before declaring text_lines when I declared the 'fid' variable as the following:
fid = fopen(FileName); and it didn't complain at that line, but it went further down my code and the error message pointed out at the 'text_lines' code line.

Any reasons why the 'length' and/or 'dataread' functions aren't wlecoming the char() function inside it, or why am I having that error in the first place.

Here's my code for your observations:
function Level2_WF_iv(block)

function setup(block)
% Register number of ports.
block.NumInputPorts = 2; % d from the Entity Gen. block.
block.NumOutputPorts = 10;

% Setup port properties to be dynamically inherited.

% Override input port properties.
% d; used for indexing
block.InputPort(1).DimensionsMode = 'Fixed';
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).SamplingMode = 'Sample';
block.InputPort(1).DirectFeedthrough = true;
% FileName
block.InputPort(2).DimensionsMode = 'Fixed';
block.InputPort(2).Dimensions = -1;
block.InputPort(2).DatatypeID = 3; % uint8
block.InputPort(2).Complexity = 'Real';
block.InputPort(2).SamplingMode = 'Sample';
block.InputPort(2).DirectFeedthrough = true;

% Override output port properties.

block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';

block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('Outputs', @Outputs);

function SetInpPortDims(Block, idx, di)
Block.InputPort(idx).Dimensions = di;

function Outputs(block)
FileName = char(block.InputPort(1).Data); This is where I reverse back the Input from 'uint8' into a 'string'
% FileName = '120percent.txt';
fid = fopen(FileName);
if block.InputPort(1).Data < 1
block.InputPort(1).Data = 1;
text_lines = length(dataread('file', FileName, '%s', 'delimiter', '\n'));
if block.InputPort(1).Data <= text_lines
a = textscan(fid, '%f%f%f%f%f%f%f%s', 1, 'delimiter', '\t', 'headerlines', block.InputPort(1).Data-1); % 'emptyvalue', NaN('double')
block.OutputPort(1).Data = a{1}; % J_ID
block.OutputPort(2).Data = a{2}; % T_ID
block.OutputPort(3).Data = a{3}; % NoT
block.OutputPort(4).Data = a{4}; % Cores
block.OutputPort(5).Data = a{5}; % T_ET
block.OutputPort(6).Data = a{6}; % J_ET
Deps = a{8}; % Raw values with (\) between Deps.
num_slash = length(findstr(mat2str(cell2mat(Deps)), '/'));
extract = sscanf(cell2mat(Deps), '%d/')';
len_num = length(extract);
len_nan = num_slash - len_num + 1;
block.OutputPort(7).Data(1:len_num) = extract;
block.OutputPort(7).Data(len_num+1:len_num+len_nan) = NaN('double');
block.OutputPort(8).Data = a{7} + (a{5} * 1.2); % T_Deadline = RT + (T_ET * 1.2)
block.OutputPort(9).Data = a{7}; % Release Time
block.OutputPort(10).Data = a{7} + (a{6} * 1.2); % J_Deadline = RT + (J_ET * 1.2)
block.OutputPort(2).Data = NaN('double');

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.