📄 simpow2psat
字号:
}
$npq >= 0 && printf OUT " ];\n\n";
# -----------------------------------------------------------------------
# write Shunt.con
# -----------------------------------------------------------------------
$nsh >= 0 && print OUT "Shunt.con = [ ...\n";
$format = "%4d $pbase %6.2f $fbase %8.5f %8.5f %2d;\n";
for ($i = 0; $i <= $nsh; $i++) {
if ($psh[$i] != 0 or $qsh[$i] != 0) {
$h = $shbus[$i];
printf OUT $format,$h+1,$vbsh[$i],$psh[$i],$qsh[$i],
$shstatus[$i];
}
}
$nsh >= 0 && printf OUT " ];\n\n";
# -----------------------------------------------------------------------
# write Line.con
# -----------------------------------------------------------------------
if ($nline >= 0) {
print OUT "Line.con = [ ...\n";
$format = "%4d %4d %6.2f %6.2f $fbase 0 " .
"%8.5f " x 6 . "%7.3f %7.3f 0 %2d\n";
# TRANSMISSION LINES FIRST ...
for ($i = 0; $i <= $nline; $i++) {
if ($kt[$i] == 0) {
printf OUT $format,$busfr[$i]+1,$bustt[$i]+1,
$tfsb[$i],$linevb[$i],$kt[$i],$rest[$i],
$reat[$i],$susc[$i],$ratio[$i],$phas[$i],
$imax[$i],$pmax[$i],$linestatus[$i];
}
}
# ... AND TRANSFORMERS AT THE END
for ($i = 0; $i <= $nline; $i++) {
if ($kt[$i]) {
printf OUT $format,$busfr[$i]+1,$bustt[$i]+1,
$tfsb[$i],$linevb[$i],$kt[$i],$rest[$i],
$reat[$i],$susc[$i],$ratio[$i],$phas[$i],
$imax[$i],$pmax[$i],$linestatus[$i];
}
}
print OUT " ];\n\n";
}
# -----------------------------------------------------------------------
# write Conv.con
# -----------------------------------------------------------------------
if ($ncv == -2) { # skip converter data
print OUT "Conv.con = [ ...\n";
$format = "%4d %4d %4d %7.2f %7.2f %8.5f %8.5f " .
"%2d %7.2f %8.5f %8.5f %8.5f;\n";
for ($i = 0; $i <= $ncv; $i++) {
printf OUT $format,$cvbus[$i]+1,$cvbusdc1[$i]+1,$cvbusdc2[$i]+1,
$cvidn[$i],$cvudion[$i],$cvdx[$i],$cvdr[$i],$cvtyp[$i],
$cvio[$i],$cvdi[$i],$cvamin[$i],$cvgmin[$i];
}
print OUT " ];\n\n";
}
# -----------------------------------------------------------------------
# write Sreact.con
# -----------------------------------------------------------------------
if ($nsr == -2) { # skip series reactance data
print OUT "Sreact.con = [ ...\n";
$format = "%4d %4d %2d %2d %8.5f %8.5f %8.5f %2d;\n";
for ($i = 0; $i <= $nsr; $i++) {
printf OUT $format,$srbus1[$i]+1,$srbus2[$i]+1,$srno[$i],
$srtype[$i],$srr[$i],$srl[$i],$srx[$i],$srncon[$i];
}
print OUT " ];\n\n";
}
# -----------------------------------------------------------------------
# write Twt.con
# -----------------------------------------------------------------------
if ($ntw >= 0) {
print OUT "Twt.con = [ ...\n";
$format = "%4d %4d %4d %6.2f $fbase %6.2f %6.2f %6.2f " .
"%8.5f " x 6 . "0 0 0 0 0 0 0 0 0 0 %2d;\n";
for ($i = 0; $i <= $ntw; $i++) {
printf OUT $format,$bus1[$i]+1,$bus2[$i]+1,$bus3[$i]+1,
$twsb[$i],$vb1[$i],$vb2[$i],$vb3[$i],$r12[$i],$r13[$i],$r23[$i],
$x12[$i],$x13[$i],$x23[$i],$twstatus[$i];
}
print OUT " ];\n\n";
}
# -----------------------------------------------------------------------
# write Syn.con
# -----------------------------------------------------------------------
$nsyn >= 0 && print OUT "Syn.con = [ ...\n";
$format = "%4d %6.2f %6.2f $fbase %2d " . "%8.5f " x 14 .
" 0 0 %6.2f %6.2f 0 0 0 1 1;\n";
for ($i = 0; $i <= $nsyn; $i++) {
$h = $synbus[$i];
printf OUT $format,$h+1,$gbas[$i],$kvb[$h],$gentype[$i],
$xl[$i],$ra[$i],$xd[$i],$xdp[$i],$xdb[$i],
$td0p[$i],$td0b[$i],$xq[$i],$xqp[$i],$xqb[$i],$tq0p[$i],
$tq0b[$i],$mstt[$i],$damp[$i],$pf[$i],$qf[$i];
}
$nsyn >= 0 && print OUT " ];\n\n";
# -----------------------------------------------------------------------
# write Exc.con
# -----------------------------------------------------------------------
$nexc >= 0 && print OUT "Exc.con = [ ...\n";
$format = "%4d %2d " . "%8.5f " x 6 . "0 " . "%8.5f " x 2 . "0.0006 0.9 1;\n";
for ($i = 0; $i <= $nexc; $i++) {
for ($h = 0; $h <= $nsyn; $h++) {
if ($synvreg[$h] == $exccode[$i]) {
printf OUT $format,$h+1,$exctype[$i],$excvrmax[$i],
$excvrmin[$i],$excka[$i],$excta[$i],$exckf[$i],
$exctf[$i],$excte[$i],$exctr[$i];
}
}
}
$nexc >= 0 && print OUT " ];\n\n";
# -----------------------------------------------------------------------
# write Bus.name
# -----------------------------------------------------------------------
if ($nbus >= 0) {
print OUT "Bus.names = { ...\n";
$h = ($nbus+1) % 5;
if ($h == 0) { $h = 5; }
if (($nbus+1) > 5) {
for ($i = 0; $i <= $nbus-$h; $i+=5) {
print OUT " '$busname[$i]'; '$busname[$i+1]'; " .
"'$busname[$i+2]'; '$busname[$i+3]'; '$busname[$i+4]';\n";
}
}
print OUT " ";
for ($i = $nbus-$h+1; $i <= $nbus-1; $i++) {
print OUT "'$busname[$i]'; ";
}
print OUT "'$busname[$nbus]'};\n\n";
}
# -----------------------------------------------------------------------
# write PV.name
# -----------------------------------------------------------------------
if ($npv == -2) { # skip PV names
print OUT "PV.name = { ...\n";
$h = ($npv+1) % 5;
if ($h == 0) { $h = 5; }
if (($npv+1) > 5) {
for ($i = 0; $i <= $npv-$h; $i+=5) {
$j = $pvidx[$i];
print OUT " '$genname[$j]'; '$genname[$j+1]'; " .
"'$genname[$j+2]'; '$genname[$j+3]'; '$genname[$j+4]';\n";
}
}
print OUT " ";
for ($i = $npv-$h+1; $i <= $npv-1; $i++) {
$j = $pvidx[$i];
print OUT "'$genname[$j]'; ";
}
print OUT "'$genname[$pvidx[$npv]]'};\n\n";
}
# -----------------------------------------------------------------------
# write PQgen.name
# -----------------------------------------------------------------------
if ($npg == -2) { # skip PQgen names
print OUT "PQgen.name = { ...\n";
$h = ($npg+1) % 5;
if ($h == 0) { $h = 5; }
if (($npg+1) > 5) {
for ($i = 0; $i <= $npg-$h; $i+=5) {
$j = $pgidx[$i];
print OUT " '$genname[$j]'; '$genname[$j+1]'; " .
"'$genname[$j+2]'; '$genname[$j+3]'; '$genname[$j+4]';\n";
}
}
print OUT " ";
for ($i = $npg-$h+1; $i <= $npg-1; $i++) {
$j = $pgidx[$i];
print OUT "'$genname[$j]'; ";
}
print OUT "'$genname[$pgidx[$npg]]'};\n\n";
}
# -----------------------------------------------------------------------
# write SW.name
# -----------------------------------------------------------------------
if ($nsw == -2) { # skip SW names
print OUT "SW.name = { ...\n";
$h = ($nsw+1) % 5;
if ($h == 0) { $h = 5; }
if (($nsw+1) > 5) {
for ($i = 0; $i <= $nsw-$h; $i+=5) {
$j = $swidx[$i];
print OUT " '$genname[$j]'; '$genname[$j+1]'; " .
"'$genname[$j+2]'; '$genname[$j+3]'; '$genname[$j+4]';\n";
}
}
print OUT " ";
for ($i = $nsw-$h+1; $i <= $nsw-1; $i++) {
$j = $swidx[$i];
print OUT "'$genname[$j]'; ";
}
print OUT "'$genname[$swidx[$nsw]]'};\n\n";
}
# -----------------------------------------------------------------------
# write Conv.name
# -----------------------------------------------------------------------
if ($ncv == -2) { # skip Converter names
print OUT "Conv.name = { ...\n";
$h = ($ncv+1) % 5;
if ($h == 0) { $h = 5; }
if (($ncv+1) > 5) {
for ($i = 0; $i <= $ncv-$h; $i+=5) {
print OUT " '$cvname[$i]'; '$cvname[$i+1]'; " .
"'$cvname[$i+2]'; '$cvname[$i+3]'; '$cvname[$i+4]';\n";
}
}
print OUT " ";
for ($i = $ncv-$h+1; $i <= $ncv-1; $i++) {
print OUT "'$cvname[$i]'; ";
}
print OUT "'$cvname[$ncv]'};\n\n";
}
# -----------------------------------------------------------------------
# close output data file
# -----------------------------------------------------------------------
close(OUT) || die "Cannot close $ARGV[1]: $!\n";
print "Conversion completed.\n";
# -----------------------------------------------------------------------
# function that assigns file or default values
# -----------------------------------------------------------------------
sub assign {
my $value = $_[1];
if (exists $data{$_[0]}) {
$value = $data{$_[0]};
}
return $value;
}
# -----------------------------------------------------------------------
# function that assigns the status of a component
# -----------------------------------------------------------------------
sub status {
my $status;
if (assign("NCON",0)) {
$status = 0;
} else {
$status = 1;
}
return $status;
}
# -----------------------------------------------------------------------
# function that discards comment region in the data file
# -----------------------------------------------------------------------
sub discom {
while (defined($_ = shift(@data))) { last if /^\$ENABLE/; }
}
# -----------------------------------------------------------------------
# function that takes care of the $INCLUDE statement
# -----------------------------------------------------------------------
sub include {
my (@temp,@mydata);
@temp = split /\s*[\s=]\s*/, $_;
$temp[1] =~ tr/[A-Z]/[a-z]/;
$temp[1] =~ s/\\/\//g;
#$temp[1] =~ s/\//$file_separator/g;
$temp[1] = $dir . $temp[1];
if (open(IN,$temp[1])) {
print "Including file <" . $temp[1] . ">\n";
@mydata = <IN>;
unshift @data , @mydata;
close(IN);
} else {
print "Cannot open include file $temp[1]: $!\n";
}
}
# -----------------------------------------------------------------------
# function that sorts hash values by their index value
# -----------------------------------------------------------------------
#sub byindex {
# my ($x,$y);
# $x = $nodes{$a};
# $y = $nodes{$b};
# $x->{IDX} <=> $y->{IDX}
#}
# -----------------------------------------------------------------------
# function that returns the data in a hash {parameter,value}
# -----------------------------------------------------------------------
sub splitdata {
my ($h,$i,@temp,%mydata);
# assign firstline for the first time
if ($firstline eq "NULL") {
while (defined($_ = shift(@data))) {
chomp;
next if /^!/;
if (/^\$DISABLE/) { discom(); next; }
if (/^\$INCLUDE/) { include(); next; }
if (/^END/) {
$firstline = "END";
$mydata{"BUS1"} = "END";
return %mydata;
}
$_ =~ s/^\s*//;
next if (!$_);
$firstline = $_;
last;
}
}
$firstline =~ s/^\s*//;
@temp = split /\s*[\s=]\s*/, $firstline;
$h = shift;
if ($h == -1) {
for ($i = 1; $i <= @temp-1; $i++) {
if ($temp[$i] eq "TYPE") {
if ($temp[$i+1] eq "NODE") { $h = 1; }
if ($temp[$i+1] eq "TREG") { $h = 2; }
if ($temp[$i+1] eq "TR3") { $h = 3; }
if ($temp[$i+1] eq "REGION") { $h = 2; }
if ($temp[$i+1] eq "CONV") { $h = 1; }
last;
}
}
} elsif ($h == -2) {
$h = 2;
for ($i = 1; $i <= @temp-1; $i++) {
if ($temp[$i] eq "NW") {
$h = $temp[$i+1];
last;
}
}
}
for ($i=1; $i<=$h; $i++) { $mydata{"BUS" . $i} = shift(@temp); }
for ($i = 0; $i <= @temp-1; $i+=2) {
$mydata{$temp[$i]} = $temp[$i+1];
}
while (defined($_ = shift(@data))) {
chomp;
next if /^!/;
if (/^\$DISABLE/) { discom(); next; }
if (/^\$INCLUDE/) { include(); next; }
if (/^END/) {
$firstline = "END";
last;
}
if (/^\s{0,3}\w+/) {
$firstline = $_;
last;
}
$_ =~ s/^\s*//;
next if (!$_);
@temp = split /\s*[\s=]\s*/, $_;
for ($i = 0; $i <= @temp-1; $i+=2) {
$mydata{$temp[$i]} = $temp[$i+1];
}
}
return %mydata;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -