The WDLANG method
The WDlang method is used to write a control module in WDlanguage as defined in the Windev development environment. Help on this language is available on the site http://www.pcsoft.fr.
This functionality, carried out in WinDev, is intended to offer an alternative to the current DDE link with MATLAB or SCILAB or to the Fortran interface used with the FLUVIA and / or SIRENE programs for programming regulation modules. This new functionality does not require any third-party software, unlike the DDE MatLab link which requires the MatLab software, the DDE SciLab link which requires the SciLab software (free software under the GNU license) or the Fortran interface which requires a Fortran compiler (Digital or Intel).
This window offers an operation similar to that of the DDE MATLAB or SCILAB links. It applies laws to input data (Y, YT, Z) to generate output data (U) calculation results and possibly using parameters (PARA). Like MATLAB, this window offers the user the possibility of writing their own calculation laws. The variables Y, YT, Z and U are optional, you don’t have to define and use them all. One can for example just use Z variables to visualize them numerically or graphically, or one can just use U variables to modify them according to time for example, or read them on an external file (Open Loop type command). All of them can of course be used for example to calculate U commands from measured variables Z, from controlled variables Y, possibly assigned with YT setpoints (Closed Loop type command).
Here is an overview of the window, composed in the upper part of the data tables, results, and in the lower part of the algorithm to be executed.
The window receives the data in the form of four tables of reals called "Y, YT, Z and PARA" that the Fluvia and Sirene programs for hydraulic calculation in permanent and transient mode respectively (written in Fortran) provide information at each regulation time step.
The window will then execute a code (calculation law), entered by the user or even loaded from a text file. If the "wdroutine.txt" file exists in the data subdirectory, it will be loaded on the first call. Otherwise it will be possible to select another file with a .txt extension, or to write it in the input window (and save it).
The purpose of this law is, for example, to inform the result table “U” by following the algorithm of the calculation law (written in WLanguage).
The Fluvia or Sirene program informs the input tables (Y, YT, Z PARA) at each regulation time step, starts the calculation of the algorithm, recovers the calculated output variables (U) as well as the other modifiable variables on the screen.
You can switch the window to invisible mode to speed up the calculations (the display of the window and the calculations are not performed until the next time you get started). One can also ask to take back control only in several steps of computation time (or at a future moment).
The user can then write code in WLanguage in the control provided for this purpose in the lower part of the window, save it as a text file, or load an existing file.
Compile button: Compiles the code written in the text area. This phase is necessary if the code has been modified, or if another file has been loaded. Messages are indicated if there are compilation errors, or if on the contrary everything went well.
Execute button: Executes the last successfully compiled code, without incrementing the time, and without returning to the hydraulic calculation of Fluvia or Sirene.
Continue button: Executes the last successfully compiled code and gives control to the Fluvia or Sirene program, to repeat the hydraulic simulation.
A certain number of variables are accessible and modifiable from the code:
The PARA variables correspond to the parameter table. It is displayed on the right of the window. This array is sized to 50 real variables in current versions of SIC^2, but may be increased as needed for future versions (it was 10, 20 or 22 variables in previous SIC versions). These are persistent variables between 2 calls to the code. The first 5 PARA variables are used by the WDLANG regulation module. They can be modified by the code but this will have consequences on the functioning of the module:
PARA [1] for visible window with refreshing of the values at each DTU (if PARA [1] = 2) or invisible (if PARA [1] = 1) except screen input (read on the .xml data file, in the data module specific, modifiable on screen)
PARA [2] for counter for screen entry (max value) (idem)
PARA [3] for counter for screen entry (current value)
PARA [4] for counter for execution of the calculation (max value) (read on .reg, not modifiable on the screen)
PARA [5] for counter for execution of the calculation (current value)
Other variables are accessible:
T: current time in seconds
DT: numerical calculation time step in seconds
DTU: no control module call time in seconds
TFIN: simulation end time
NGR: regulator number
INU: number of U variables
INY: number of Y variables
INZ: number of Z variables
INPARA: number of parameters (currently 50 by default)
T and DT are controlled by the Fortran Fluvia and / or Sirene program. Modifying them will have no consequence, except in the lines of code following this modification, and for the current execution. They will be reset to their initial values on the next call. DTU can be modified either in the code, or thanks to the field "Next pause" in Number of time steps or in Time.
TFIN can be changed in the code, but only by shortening it. Otherwise there will be problems writing the results to the file, at least in binary format.
The other parameters above cannot be changed, or in any case it will have no effect.
You can also have access to 2 Chart controls (see this type of control in the Windev WdLangue language documentation on their website www.windev.com) to draw whatever you want, and for example the U variables (s) , Y, YT and / or Z. But also other things like intermediate calculations of the programmed algorithm for example. These Graphs fields are named GRFU and GRFZ. They are visible on the 2nd tab of the window. The programming code to use them is for example:
i is an integer
for i=1 to INU
grNuageAjouteDonnéeXY(GRFU,i,t,u[i])
end
for i=1 to INZ
grNuageAjouteDonnéeXY(GRFZ,i,t,z[i])
end
grDessine(GRFU)
grDessine(GRFZ)
These variables, as well as the u, y, yt, z, para, etc. can be used in upper or lower case. Before compilation, there is a formatting and modification of the source of the programmed code, so that it uses the names of the variables understandable by Windev, i.e. by using the name of the global variables (by adding the COL_RegWDLang. extension) or referring to the name of the Windev window (regWDLang.). The source thus modified is visible on the 3rd tab. This information is only given for experts who want to understand how it works. This formatting also changes the lowercase -> uppercase variables, and its visualization on the 3rd tab also indicates the line number, which facilitates debugging, since this line is indicated in the dynamic compiler message returns.
Format of the line PS : (F8.2,1X,F8.2,1X,F8.2)