function script_setEvents
%script_setEvents
%a script that defines en masse the observability and controllability properties of component FSAs
%the user must hardcode the event and FSA names
%the script also defines text files containing the observable,
%unobservable, controllable and uncontrollable event sets for the tap
%changer and capacitor bank subsystems

%set of all tap changer events 
E_tap = {'vm' 'vp' 'vn' 'tp' 'tm' 'tf' 'tton' 'ttoff' 'ttstop' 'tfail' 'tfix'};
%set of all capacitor bank events events 
E_cap = {'qm' 'qp' 'qn' 'cp' 'cm' 'cf' 'tcon' 'tcoff' 'tcstop' 'cfail' 'cfix'};

%definition of o, uo, c, uc events for tap changer and capacitor bank
%subsystems
E_tap_c = {'tp' 'tm' 'tton' 'ttoff'};
E_cap_c = {'cp' 'cpp' 'cm' 'cmm' 'tcon' 'tcoff'};
E_tap_o = {'vm' 'vp' 'vn' 'tf' 'ttstop'};
E_cap_o = {'qm' 'qp' 'qn' 'cf' 'tcstop'};

%names of the component automata
FSA_tap_names = {'T_sensor','T_switch','T_timer','T_fail','T_con1','T_con2','T_con3'};
FSA_cap_names = {'C_sensor','C_switch','C_timer','C_fail','C_con1','C_con2','C_con3'};

%creation of filies containing all the event subsets
%!!!!change the extension according to your preference, e.g., '.txt' !!!!!
writeEvents('T_Ec',E_tap_c)
writeEvents('C_Ec',E_cap_c)
writeEvents('T_Eo',E_tap_o)
writeEvents('C_Eo',E_cap_o)
writeEvents('T_Euc',E_tap_uc)
writeEvents('C_Euc',E_cap_uc)
writeEvents('T_Euo',E_tap_uo)
writeEvents('C_Euo',E_cap_uo)


E_tap_uc = setdiff(E_tap,E_tap_c);
E_cap_uc = setdiff(E_cap,E_cap_c);
E_tap_uo = setdiff(E_tap,E_tap_o);
E_cap_uo = setdiff(E_cap,E_cap_o);

for i = 1:length(FSA_tap_names)
    [FSA,S] = UMDES2MATLAB(FSA_tap_names{i});
    FSA = setEvents(FSA,E_tap_c,E_tap_o);
    MATLAB2UMDES(FSA_tap_names{i},FSA,S)
end

for i = 1:length(FSA_cap_names)
    [FSA,S] = UMDES2MATLAB(FSA_cap_names{i});
    FSA = setEvents(FSA,E_cap_c,E_cap_o);
    MATLAB2UMDES(FSA_cap_names{i},FSA,S)
end



function writeEvents(filename,E)

fid = fopen(filename,'w');
nE = length(E);
if nE>0
    for i = 1:nE-1
        fprintf(fid,E{i});
        fprintf(fid,'\n');
    end
    fprintf(fid,E{nE});
end
fclose(fid);

