You are on page 1of 3

Data transfer between Matlab and DIgSILENT

1.Description: This procedure of data exchange between Matlab and DIgSILENT was created in
order to benefit of both software advantages, thus you can use them at the same time in power
system analysis. In this way a loop was created between Matlab and DIgSILENT. The procedure
comes with a M.file (Matlab version R2009 b) and a script from a pfd file (DIgSILENT 15.1.7
x86), so the data transfer is made between these 2 files using as a link layer 2 csv files.
The data transfer between Matlab and DIgSILENT is made using two .csv files (Flag.csv and
Data.csv):
- Flag.csv - can take only one value (1 or 0): 1 - means that Matlab works and DIgSILENT waits.
0 - means that DIgSILENT works and Matlab waits.
- Data.csv - contains a vector of data and is divided in 2 (Fig. 3). First part can be filled with
variables that are necesary in the data exchange procedure (we use only 7 variables in this
example:- SizeOfDataVectMatlab, SizeOfDataVectDIg, NrOfIterations, CurrentIt, NrComVar,
NrOfDataTransFromMatlab, NrOfDataTransFromDIg), and the second part are the variables
of interest that you want to transfer from Matlab to DIgSILENT and from DIgSILENT to
Matlab.

Fig. 1. Flowchart

DIgSILENT Matlab
Data variables; Data variables;
Read Flag.csv; Read Flag.csv;
While Flag.csv = 1 { !wait for Matlab to work While Flag.csv = 0 { !wait for DIgSILENT to work
Scan Flag.csv; Scan Flag.csv;
If Flag.csv = 0{ If Flag.csv = 1{
break; break;
} }
} }
Read Data.csv; Read Data.csv;
Write Input Data; Write Input Data;
!-------------------------------------------------------- !--------------------------------------------------------
1.use values from vector InputData in your analysis 1.use values from vector InputData in your analysis
2.write variables resulted in your analysis in 2.write variables resulted in your analysis in
OutputData OutputData
!-------------------------------------------------------- !--------------------------------------------------------
Write Flag.csv = 1; Write Flag.csv = 0;

From Fig.1, is depicted the flowchart of the M.file and the script from DIgSILENT. It can be
seen that for a software to wait for the other to work, it is used a simple while loop which is
continuously scanning the Flag.csv. The while loop is breaken only when the software that works
finishes its computation and modifies the value of Flag.csv.

2.Adapt the procedure to user needs: To adapt the procedure to your problem, you must do the
followings for both software in the section that is clearly delimited:
1. Write code to read and use variables from vector InputData in your analysis (algorithms,
analysis, computations, etc.).
2. Write code to write variables resulted in your analysis in vector OutputData.
Fig. 2. Sections from Matlab and DIgSILENT where you must delete and write code as
mentioned above.

DIgSILENT Matlab

In Fig. 2 are represented the places in the files where you must write code according to what you
want to analyze. You must delete all the code lines between ‘Write code here’ and ‘END Write
code here’. These lines are the code for the example that comes with the files just to prove that
the procedure works (from DIgSILENT to Matlab is transmitted a set of round random numbers
between 70 and 100 and from Matlab to DIgSILENT is transmitted a set of random numbers
between 0 and 1).

Fig.3. Data.csv structure:

SizeOfDataVectMatlab
SizeOfDataVectDIg
NrOfIterations
CurrentIt
NrComVar Data useful in communication
NrOfDataTransFromMatlab between Matlab and DIgSILENT
NrOfDataTransFromDIg
0
0
0
var1
. Variables of interest transfered
. between Matlab and DIgSILENT
.
varn

3.How to use:
1. Modify in Matlab and DIgSILENT the path where you want to be created the csv files.

DIgSILENT Matlab
2. Determine and modify correspondingly in the script and in the M.file, the number of variables
that you want to transfer between Matlab and DIgSILENT ((NrOfDataTransFromMatlab) and
from DIgSILENT to Matlab (NrOfDataTransFromDIg)
3. Adapt the procedure to user needs: modify the script and the M.file like explain in chapter 2
Obs.: to observe better the entire process, use left part of the screen for DIgSILENT and right file
of the screen for Matlab.

4. First run the M.file and then execute the script.

Link: https://www.youtube.com/watch?v=cro_V7_vRTU&t=94s

The example that comes with the files is transferring 9 random numbers from Mat to DIg and 5
round random numbers from DIg to Mat, 500 iterations.

Soon will be finished Data exchange between Matlab and DIgSILENT v.3, in which the user
will not predefine the number of variable that will be transferred between software.

Dr.Ing. Stativa Andrei

You might also like