How to find data with specific data type.

In my code generation, my target hardware does not support double-precision float, so I want to scan my models for any doubles before generating code.
Here is an example entry from my model file of what I want to find (it is in a Stateflow chart):
data {
id 203
ssIdNumber 100
name "cntr"
linkNode [117 0 204]
scope FUNCTION_INPUT_DATA
machine 1
props {
type {
primitive SF_DOUBLE_TYPE
isSigned 1
wordLength "16"
}
}
dataType "double"
}
The following line of code does NOT work:
dataTypes = find_system(sys,'FindAll','on','LookUnderMasks','all','dataType','double');
Can anyone provide a script to find all such occurrences?

Risposte (1)

I think the safest way to check datatypes used in a model is to compile the model and check the compiled datatypes at the boundary of each block. You can do this for one block using something like:
vdp([],[],[],'compile');
d = get_param(gcb,'CompiledPortDataTypes');
vdp([],[],[],'term');
You will need to inspect 'd' to see if contains double.
(Note: if you need to disallow all floating-point types, you can simply uncheck Support: floating-point numbers in the Configuration Parameters window)

4 Commenti

Unless I did this wrong, it returned an empty struct:
>> Kln_Cycle([],[],[],'compile');
>> d = get_param(gcb,'CompiledPortDataTypes');
>> Kln_Cycle([],[],[],'term');
>> d
d =
0x0 struct array with fields:
Inport
Outport
Enable
Trigger
State
LConn
RConn
Ifaction
>> d.Inport
>> d.Outport
>> d.Enable
>> d.Trigger
>> d.State
>> d.LConn
>> d.RConn
>> d.Ifaction
"gcb" basically returns the path to a selected block. It looks like you may not have any block in your model selected? Alternatively, you can use a specific block's path:
d = get_param('Kln_Cycle/In1','CompiledPortDataTypes');
Sorry, obviously gcb would only select one block. I just need to scan all blocks.
However, the doubles that are in my system are internal data definitions within Stateflow chart functions. How do you drill down to access those too? I have been trying all sorts of things, but can not seem to get to them.
I've used the Stateflow API in the past to look inside Stateflow objects, but I don't know what the exact commands to use in your case might be. Perhaps going through the documentation will give you some ideas.

Accedi per commentare.

Categorie

Prodotti

Richiesto:

il 1 Ago 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by