Method and system for preparing block diagrams for code generation
A method for preparing block diagrams having one or more blocks for code generation in a computing environment comprising a model editor, a data definition tool and a code generator. The block diagram is opened in the model editor, wherein a first block is a hierarchical block comprising a plurality of subordinate blocks, at least one input port and at least one output port connected by signals. Minimum values and maximum values are received for the input and output ports, determining scaling parameters for the input and output ports based on the received minimum and maximum values. Scaling parameters are determined for each subordinate block in the first block, wherein the scaling parameters of at least one subordinate block are determined based on the scaling parameters of at least one output port. Also, a method for generating program code, a non-transitory computer readable medium and a computer system are provided.
1. A method for preparing a block diagram comprising one or more blocks for code generation in a technical computing environment, the technical computing environment comprising a model editor, a data definition tool, and a code generator, the technical computing environment being executed by at least one processor of a host computer, the method comprising:
opening the block diagram in the model editor, wherein a first block is a hierarchical block comprising a plurality of subordinate blocks, at least one input port and at least one output port, wherein signals connect the at least one input port, the subordinate blocks and the at least one output port;
receiving minimum values and maximum values for the at least one input port and the at least one output port;
determining scaling parameters for the at least one input port and the at least one output port based on the received minimum and maximum values;
determining scaling parameters for at least one subordinate block in the first block, wherein the scaling parameters of the at least one subordinate block are determined based on the scaling parameters of at least one output port of the at least one output ports;
verifying if at least one scaling condition is fulfilled for the at least one subordinate block;
generating a warning to a user based on predefined scaling conditions; and
generating production code based on the block diagram and the scaling parameters,
wherein the at least one scaling condition is not fulfilled if a range of values for an internal signal of non-Boolean type comprises less than three possible values.
2. The method of claim 1 , wherein the scaling parameters for subordinate blocks are determined iteratively, and wherein an order of preparing subordinate blocks is predefined for the first block.
3. The method of claim 2 , wherein the first block is a library block and wherein the library block comprises an executable script for scaling the first block and/or a dedicated definition document.
4. The method of claim 2 , wherein the minimum and the maximum values for the at least one input port and the at least one output port are stored in the data definition tool, and wherein the scaling parameters are determined based on the stored values.
5. The method of claim 1 , further comprising outputting a suggestion for changing the maximum value, the minimum value or the scaling parameters of the at least one input port or of the at least one output port.
6. The method of claim 1 , wherein the scaling parameters for each subordinate block are determined based on the scaling parameters of adjacent blocks or the input ports or the output ports upstream of the subordinate block.
7. The method of claim 1 , wherein the scaling parameters comprise a data type, a least significant bit and an offset.
8. The method of claim 1 , wherein the scaling parameters for atomic blocks are stored in and retrieved from the data definition tool.
9. The method of claim 1 , further comprising: executing the block diagram including the first block, the at least one subordinate block, and signal paths in a simulation engine of the technical computing environment of the host computer.
10. A method for generating source code based on a block diagram, comprising one or more blocks, in a technical computing environment, the technical computing environment comprising a model editor, a data definition tool, a simulation engine, and a code generator, the technical computing environment being executed by at least one processor of a host computer, the method comprising:
opening the block diagram in a model editor, wherein a first block is a hierarchical block comprising a plurality of subordinate blocks, at least one input port and at least one output port, wherein signals connect the at least one input port, the subordinate blocks and the at least one output port;
receiving minimum values and maximum values for the at least one input port and the at least one output port;
determining scaling parameters for the at least one input port and the at least one output port based on the received minimum and maximum values;
determining scaling parameters for at least one subordinate block in the first block, wherein the scaling parameters of the at least one subordinate block are determined based on the scaling parameters of at least one output port of the at least one output ports;
verifying if at least one scaling condition is fulfilled for the at least one subordinate block;
generating a warning to a user based on predefined scaling conditions; retrieving additional code generation settings from a data definition tool; and
generating production code based on a scaled block diagram and the additional code generation settings,
wherein the at least one scaling condition is not fulfilled if a range of values for an internal signal of non-Boolean type comprises less than three possible values.
11. A non-transitory computer-readable medium containing instructions that, when executed by a microprocessor of a computer system, cause the computer system to carry out a method according to claim 10 .
12. A computer system comprising a host computer comprising:
a microprocessor;
a random access memory;
a graphics controller connected to a display;
a serial interface connected to at least one human input device; and
a nonvolatile memory, a hard disk and/or a solid state disk, the nonvolatile memory comprising instructions that, when executed by the microprocessor, cause the computer system to carry out the method according to claim 1 .