⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwrworld2psat

📁 这是一个很适合研究和学习用的电力系统仿真软件
💻
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl -w
# PWRWORLD2PSAT converts PowerWorld data file into PSAT data file
#
# PWRWORLD2PSAT <OPTIONS> FILEINPUT <FILEOUTPUT>
#
# Author:  Federico Milano
# Date:    30-May-2005
# Version: 1.0.0
#
#E-mail:    fmilano@thunderbox.uwaterloo.ca
#Web-site:  http://thunderbox.uwaterloo.ca/~fmilano

use strict;

# -----------------------------------------------------------------------
# variable declaration
# -----------------------------------------------------------------------
my $tab = 0;
my %busname;
my %busnumb;
my %index;
my @list;
my (@idxpv, @idxsw, @idxpq, @idxsh);
my $nargin;
my $verbose = 0;
my $helpmsg = 0;
my ($i,$h,$k,$j);
my $format;
my $n = 0;
my $npv = -1;
my $nsw = -1;
my $npq = -1;
my $npl = -1;
my $nsupply = -1;
my $nsupply2 = -1;
my $nsh = -1;
my $ntw = -1;
my $ngen = 1;
my $pbas = 100;
my $nbus = -1;
my $nline = -1;
my $narea = -1;
my $flag_bus = 0;
my $flag_line = 0;
my $flag_area = 0;
my $flag_trsf = 0;
my $flag = 1;
my $value;
my $add;
my $unit;
my $length;
my $zn;
my @data;
my (@busidx,@vn,@ein,@ang,@area,@zone); 
my (@pqidx,@sa0,@sr0); 
my (@plidx,@ia0,@ir0,@za0,@zr0); 
my ($slack,$swbase,$swpgen,$swqmax,$swqmin,$swvolt); 
my (@pvidx,@pvbase,@pgen,@qmax,@qmin,@volt); 
my (@supply,@subase,@pmax,@pmin,@c0,@c1,@c2); 
my (@busfr,@busto,@rest,@reat,@susc,@tap,@phi,@iijmax,@pijmax,@sijmax,@kvbase,@kt);	    
my (@shidx,@kvsh,@bsh,@gsh);
my (@r12,@r23,@r13,@x12,@x23,@x13,@twbus1,@twbus2,@twbus3);
my (@twkv1,@twkv2,@twkv3,@twtap,@twbase);

# -----------------------------------------------------------------------
# check inputs
# -----------------------------------------------------------------------
$nargin = @ARGV;
$nargin || die "Error: No input data file.\n";
my $title1 = 'Generic PowerWorld Data Format File '.$ARGV[0];
my $title2 = '   ';

# -----------------------------------------------------------------------
# check options
# -----------------------------------------------------------------------
while ($ARGV[0] =~ /^-/) {
    if ($ARGV[0] =~ /v/) {$verbose = 1;}
    if ($ARGV[0] =~ /h/) {$helpmsg = 1;}
    shift(@ARGV);
    $nargin--;
    if ($nargin == 0) { 
	last;
    }
}

# -----------------------------------------------------------------------
# help (if requested)
# -----------------------------------------------------------------------
if ($helpmsg) {
    print "\nPWRWORLD2PSAT converts PowerWorld data files into PSAT data files.\n\n";
    print "psse2psat <options> fileinput <fileoutput>\n";
    print "  -v   verbose\n";
    print "  -h   print this help and exit\n\n";
    print "Author:   Federico Milano\n";
    print "Date:     07-June-2005\n";
    print "Version:  1.0.0\n\n";
    print "E-mail:   fmilano\@thunderbox.uwaterloo.ca\n";
    print "Web-site: http://thunderbox.uwaterloo.ca/~fmilano\n";
    die "\n";
}

# -----------------------------------------------------------------------
# define output file name (if necessary)
# -----------------------------------------------------------------------
if ($nargin == 1) {
    $ARGV[1] = $ARGV[0];
    $ARGV[1] =~ s/^d*_*/d_/;
    $ARGV[1] =~ s/[^\w\.]/_/g;
    $ARGV[1] =~ s/\..+$/.m/;
} elsif ($nargin == 0) {
    die "Error: Input file name is missing.\n";
}

# -----------------------------------------------------------------------
# open AUX data file
# -----------------------------------------------------------------------
print "Opening PowerWorld file \"$ARGV[0]\"...\n";
carret();
open(IN,$ARGV[0]) || die "cannot open $ARGV[0]: $!\n";

# -----------------------------------------------------------------------
# scan input data file
# -----------------------------------------------------------------------

while (<IN>) {
    chomp;
    unless (m/^DATA/) {next;}
    
# read BUS data

    if (m/^DATA \(BUS, \[/) {
	%index = scanfile("BUS");
	unless ($index{"BusName"}) {next;} 
	while (<IN>) {
	    chomp;
	    if (m/^\}/) {last;}
	    @data = splitdata($_);
	    $nbus++;
	    $busidx[$nbus] = $data[$index{"BusNum"}];
	    $busname{$nbus} = $data[$index{"BusName"}];
	    $busnumb{$busidx[$nbus]} = $nbus;
	    $vn[$nbus] = $data[$index{"BusNomVolt"}];
	    $ein[$nbus] = $data[$index{"BusPUVolt"}];
	    $ang[$nbus] = 0.01745329251994*$data[$index{"BusAngle"}];
	    $area[$nbus] = $data[$index{"AreaNum"}];
	    $zone[$nbus] = $data[$index{"ZoneNum"}];
	    if ($data[$index{"BusSlack"}] eq 'YES') {
		$slack = $data[$index{"BusNum"}];
	    }
	}
    }

# read LOAD data

    if (m/^DATA \(LOAD, \[/) {
	%index = scanfile("LOAD");
	unless ($index{"LoadSMW"}) {next;} 
	while (<IN>) {
	    chomp;
	    if (m/^\}/) {last;}
	    @data = splitdata($_);
	    if ($data[$index{"LoadStatus"}] ne "Closed") {next;}
	    if ($data[$index{"LoadSMW"}] != 0 || 
		$data[$index{"LoadSMVR"}] != 0) {
		$npq++;
		$pqidx[$npq] = $data[$index{"BusNum"}];
		$sa0[$npq] = $data[$index{"LoadSMW"}]/100;
		$sr0[$npq] = $data[$index{"LoadSMVR"}]/100;
	    }
	    if ($data[$index{"LoadIMW"}] != 0 || 
		$data[$index{"LoadIMVR"}] != 0 || 
		$data[$index{"LoadZMW"}] != 0 || 
		$data[$index{"LoadZMVR"}] != 0 ) {
		$npl++;
		$plidx[$npl] = $data[$index{"BusNum"}];
		$ia0[$npl] = $data[$index{"LoadIMW"}]/100;
		$ir0[$npl] = $data[$index{"LoadIMVR"}]/100;
		$za0[$npl] = $data[$index{"LoadZMW"}]/100;
		$zr0[$npl] = $data[$index{"LoadZMVR"}]/100;
	    }
	}
    }

# read GEN data

    if (m/^DATA \(GEN, \[/) {
	%index = scanfile("GEN");
	while (<IN>) {
	    chomp;
	    if (m/^\}/) {last;}
	    if (m/<SUBDATA BidCurve>/) {
		while (<IN>) {
		    if (m/<\/SUBDATA>/) {last;}		    
		}
		next;
	    }
	    @data = splitdata($_);
	    if ($index{"GenMW"}) {
		if ($data[$index{"GenStatus"}] ne "Closed") {next;}
		if ($data[$index{"BusNum"}] == $slack) {
		    $nsw++;
		    $swbase = $data[$index{"GenMVABase"}];
		    $swpgen = $data[$index{"GenMW"}]/$data[$index{"GenMVABase"}];
		    $swvolt = $data[$index{"GenVoltSet"}];
		    $swqmin = $data[$index{"GenMVRMin"}]/$data[$index{"GenMVABase"}];
		    $swqmax = $data[$index{"GenMVRMax"}]/$data[$index{"GenMVABase"}];
		} else {
		    $npv++;
		    $pvidx[$npv] = $data[$index{"BusNum"}];
		    $pvbase[$npv] = $data[$index{"GenMVABase"}];
		    $pgen[$npv] = $data[$index{"GenMW"}]/$data[$index{"GenMVABase"}];
		    $volt[$npv] = $data[$index{"GenVoltSet"}];
		    $qmin[$npv] = $data[$index{"GenMVRMin"}]/$data[$index{"GenMVABase"}];
		    $qmax[$npv] = $data[$index{"GenMVRMax"}]/$data[$index{"GenMVABase"}];
		}
		$nsupply++;
		$supply[$nsupply] = $data[$index{"BusNum"}];
		$subase[$nsupply] = $data[$index{"GenMVABase"}];
		$pmin[$nsupply] = $data[$index{"GenMWMin"}]/$data[$index{"GenMVABase"}];
		$pmax[$nsupply] = $data[$index{"GenMWMax"}]/$data[$index{"GenMVABase"}];
		if ($index{"GenIOA"}) {$c0[$nsupply] = $data[$index{"GenIOA"}];}
		if ($index{"GenIOB"}) {$c1[$nsupply] = $data[$index{"GenIOB"}];}
		if ($index{"GenIOC"}) {$c2[$nsupply] = $data[$index{"GenIOC"}];}
	    } elsif ($index{"GenIOA"}) {
		$nsupply2++;
		$c0[$nsupply2] = $data[$index{"GenIOA"}];
		$c1[$nsupply2] = $data[$index{"GenIOB"}];
		$c2[$nsupply2] = $data[$index{"GenIOC"}];
	    }
	}
    }

# read SHUNT data

    if (m/^DATA \(SHUNT, \[/) {
    %index = scanfile("SHUNT");
    if ($index{"Found"}) {
	while (<IN>) {
	    chomp;
	    if (m/^\}/) {last;}
	    if ($data[$index{"SSStatus"}] ne "Closed") {next;}
	    @data = splitdata($_);
	    if ($data[$index{"SSCMode"}] eq "Fixed") {
		$nsh++;
		$shidx[$nsh] = $data[$index{"BusNum"}];
		$kvsh[$nsh] = $vn[$busnumb{$data[$index{"BusNum"}]}];
		$gsh[$nsh] = 0;
		$bsh[$nsh] = $data[$index{"SSNMVR"}]/100;
	    }
	}
    }
}

# read BRANCH data

    if (m/^DATA \(BRANCH, \[/) {
	%index = scanfile("BRANCH");
	unless ($index{"LineR"}) {next;} 
	while (<IN>) {
	    chomp;
	    if (m/^\}/) {last;}
	    @data = splitdata($_);
	    if ($data[$index{"LineStatus"}] ne "Closed") {next;}
	    $nline++;
	    $busfr[$nline] = $data[$index{"BusNum"}];
	    $busto[$nline] = $data[$index{"BusNum:1"}];
	    $kvbase[$nline] = $vn[$busnumb{$data[$index{"BusNum"}]}];
	    $kt[$nline] = $vn[$busnumb{$data[$index{"BusNum"}]}] / 
		$vn[$busnumb{$data[$index{"BusNum:1"}]}];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -