McSimAPN Programme structure.
MJMcCann-Consulting

Block structure, net list, dynamic arrays.
MJMcCann-Consulting Logo

McSimAPN Programme structure.
Instead of going with the more modern OOP approach I decided to stick with essentially the same form that I used with the first of these simulation tools around 1993.
The blocks are "records", not objects, using Borland Delphi Pascal, and are in an array. Along with these records which contain all the data for each individual block, is a collection of system parameters which record the state of, and serve to control the progress of the simulation.
This provides a set of Global variables and constants which are then available to every part of the programme.
In this same globally available unit is the collection of routines which provide for the actions, display, creation initialization, saving and restoring of the blocks that form a model.
There are other units that provide for the screen display and the menus thereon and for the temporary Windows that pop-up to show and edit information about the blocks.
There is also provision for linking to a Microsoft Excel spreadsheet which can use its VBA capabilities as a live programmable, multi-input, multi output block which appears on the diagram.
When compiled McSimAPN is a single executable file that takes up less than 1MB. It does not require any installation other than copying it to a convenient directory, whence it can be executed by double clicking on the icon, or dragging and dropping a text file icon over its icon.
Text Files are used for storing models at any stage during a run and for saving a recording made to produce the graph. These files can be edited in any text editor. The parser for input of models can read any text file without complaint, but will only make a model component when it finds a suitably arranged line of text. The text files can be read into a spreadsheet. Part models can be modified in a spreadsheet, for example: to create repetitive structures or to change the ID numbering.

Activation and Running
The essential code, that defines what each block type does, is listed with the block descriptions.
The explanation of the computational process of running the model (as distinct from what the user does) is described in the description of Operation.

Block Record Contents
Each block has stored the following items:
ID :integer; //The ID number, actually same as the index into the array of records.
Ty :char; // a single character that defines the type of block e.g 'A', '@'
name :string[10]; //a place to store a name, defaults to type and ID
OnOff :integer; //only two values, 0 or 1 are used: is block active[1] or not [0]
Displ :integer; //defines how the item will be displayed: Minimal, Type only, Type+ID, Name
State :integer; //for ABCD blocks this is state-machine state, for others it is the mode of operation.
Xn, Yn :integer; //locations in pixels on screen, usual Windows rules, X pos to right, Y pos down. An, Bn, Cn, Dn, Pn :integer; //connections to other blocks
aa,bb,cc,dd,pp :real; //extra values to be added to input from connections or used as independent parameters
Vn :real; // output Value as seen by other blocks in normal mode. May be used as NextEvent time
Store :array of real; //dynamic array, only some blocks use it. Place to keep records etc as needed
Comment :string; //space to put comment about the block. Stays in the record and the saved model file

System Variables and Constants
CONSTANTS:
BlocksMax=1000; //maximum size of model
BlocksTiming=20; //blocks set aside for giving a model access to system timing controls. System updates them, so they appear as psuedo-constants
LastSystemBlock=100; // other blocks set aside for system use or for users to create predefined blocks
StBoCo=5.67051E-8; //Stephan Boltzman Constant (used in thermal radiation block. (SI units, of course)
Ln10=2.302585093; //natural log of 10
TinyNumber=10e-20; //to be used to avoid embarassing zeros
BigNumber=10e20; // to put an upper bound on things
RcTapeMax=10000; //maximum number of records stored as simulation proceeds.

TIMING VARIABLES:
time, starttime, fintim , //independent variable = time, range of simulation
HoldStep, HoldNext, Delt, TinyDelt, //stepping for simulation
GrDel, GrNext, //stepping for graph
Running, Stop, Hold, XLrunning, // what's going on
HoldBlock, // available link for some block to freeze the run

DISPLAY CONTROL:
GrMinT, GrMaxT, GrMinY, GrMaxY, //boundaries for graph. May be changed in running
ScaleOrigin,ScaleFactor,ColourMin,ColourMax : real; //settings for standard scales
GrWidth,GrHeight,GrLeft,GrTop, GrVertIntv, GrHorIntv, //layout for graph
NumberDisplay : integer; //0=off,1=IDs,2=Scaled values,3=actualvalues
FullRefresh, GridOn, GrPlotVisible, NodesRefresh, Animation, //display control
FoundAnything :BOOLEAN ; // did the click come on a block
ChosenBlock, LastX, LastY, RunSecs: integer //what and where on the screen

RECORDING, WRITING:
RcTrackMax, RcTapeLastPt, //what and where in the recording process
ReadCount, BlocksMaxUsed, // sizes of model

FILES (IN USE):
DataFile, SaveFile, TapeFile, ReadType : string;
DataF, SaveF, tapeF : textfile; //file names

MJMcCann-Consulting

Help Index:
Index/Search

Background
Simulation Concepts
Continuous Systems
Discrete Systems
McSimAPN Structure
McSimAPN Operation

Using McSimAPN
Start McSimAPN
Save Model,data
Create Blocks
Run-Hold-Reset
Link Excel+VBA

PetriNet Block Types
A activity/action
B belt conveyor
C container/constant
D diverter(random)

Analogue Block Types
E exponents
F flux/flow
G function Generator
H hysteresis
I integrator
J inductor
K logic element
L logarithms
M memory
N note/label
O oscilloscope/graph
p not assigned
Q quantizer/rounding
R relay on/off
S sin/asin/atan
T timer/clock
U user link Excel
V visual voltmeter
W sWitch selector/MUX
X multiply
y not assigned
Z random (fuZZ)
& signed summation
% division/difference
@ access/move values

Invitation. McCann can help if you have a design or operational problem that needs some technical support that is outside your team's experience, some quantitative assessment of what is really the cause of the difficulties, some design alternatives or just a fresh look by an intelligent interrogator.
If you have a problem with the behaviour of a market sector, plant, process or item of equipment and would like to get a quantitative handle on it to improve yield or optimise performance, then contact us. We are always ready to give a little time to discuss a new puzzle, in confidence, of course. We'll only worry about fees when we have some defined work. We can be flexible about how we work with you.
Top
MJMcCann-Consulting,
POB 902,
Chadds Ford PA
19317 USA.
T: 1 302 654-2953
F: 1 302 429 9458
E: mjmccann@iee.org
Request. Please let us know how you found this software and your interests by sending an email to mjmccann@iee.org Thank you Date: 2012.02.26
File: struct.htm