function [bus, line] = write_pst(nbus, nbranch, connect, elec, busnames); % % % Uses the output of the read_ngc and order_ngc functions to produce matrices % "bus" and "branch", suitable for use as the input data (bus and line) for % the Matlab Power System Toolbox, as described below. % % Note that only kV(n), from, to, Rpu, Xpu and Bpu are specifically given in % the input data used by the read_ngc function - other parameters are estimates. % % % Bus column format, with examples: % % # |V| < | Vs' ____________ | % Vs |--------------> <-------|------|----------|___R + jX___|----------|------| Vr % | > < | _|_ _|_ | % FROM bus ___ B/2 B/2 ___ TO bus % | | disp(' ') disp(' write_pst.m ') disp([' For the moment, a very basic setup: only branch impedances and bus numbers are known.',sprintf('\n'), ... ' All other details will be filled in to cause tap-changing to be ignored, and bus types to be',sprintf('\n'), ... ' to be all PQ apart from the first (swing). No loads or generation are included.',sprintf('\n'), ... ' Liberal limits are put on bus voltage, Q generation, etc.',sprintf('\n'), ... ' Further development is needed to make use of any generator and load data that can',sprintf('\n'), ... ' be found for the system.',sprintf('\n'),sprintf('\n') ]) % For the moment, a very basic setup: only branch impedances and bus numbers are known. % All other details will be filled in to cause tap-changing to be ignored, and bus types % all to be PQ apart from the first (swing). No loads or generation are included. % Liberal limits are put on bus voltage, Q generation, etc. % Further development is needed to make use of any generator and load data that can % be found for the system. % Make bus matrix % zeros bus = zeros(nbus,15); % bus# |V|pu ','s'); if isempty(write_file) | write_file~='n', write_file = 'y'; end if write_file=='n', return end % wait till non-empty string input, for filename while 1, disp(' ') filename = input(' Enter the desired filename (it will get a ''.m'' extension) > ','s'); if ~isempty(filename), break end end % add the .m extension, filename = [ filename, '.m' ]; % find hostname, to go in the written file if isunix, % qeury for hostname, and remove end-of-line character [dummy,nameofhost] = unix('hostname'); nameofhost = nameofhost(1:length(nameofhost)-1) clear dummy else nameofhost = ' '; end % open the file for writing, and insert formatted data and comment strings fileid = fopen(filename,'w'); % fprintf(fileid,['% ',filename,sprintf('\n'),'% ',sprintf('\n'),'% Loadflow data in Power System Toolbox format.', ... % sprintf('\n'),'% ',sprintf('\n'),'% Written by ''write_pst.m'', ',datestr(now), ... % sprintf('\n'),'% ',sprintf('\n'),'% ',sprintf('\n'),sprintf('\n'),' bus = [ ...',sprintf('\n') ]); fprintf(fileid,['%% %s \n%% \n%% System loadflow data, in Power System Toolbox format.' ... '\n%% \n%% Written by write_pst, %s , on %s \n%% \n \n bus = [ ... \n'], ... filename, datestr(now), nameofhost); fprintf(fileid,[' %3.0f %1.4f %3.2f %3.4f %3.4f %3.4f %3.4f '... '%3.4f %3.4f %1.0f %3.2f %3.2f %3.1f %1.3f %1.3f \n'] ,bus'); fprintf(fileid,']; \n\n line = [ ... \n'); fprintf(fileid,[' %3.0f %3.0f %3.4f %3.4f %3.4f '... '%1.2f %1.2f %1.2f %1.2f %1.2f \n'] ,line'); fprintf(fileid,']; \n'); fclose(fileid); % display exit status disp(' ') disp([' write_pst : file ',filename,' written.']) disp(' ')