📄 webflow2psat
字号:
#!/usr/bin/perl -w# WEBFLOW2PSAT converts WEBFLOW data file into PSAT data file## WEBFLOW2PSAT <OPTIONS> FILEINPUT <FILEOUTPUT>## Author: Juan Carlos Morataya# Date: 13-Nov-2005# Version: 1.0.0# # E-mail: jc.morataya@ieee.org#use strict;# -----------------------------------------------------------------------# variable declaration# -----------------------------------------------------------------------my $nargin = 0;my $verbose = 0;my $helpmsg = 0;my ($i,$h,$k);my $nbus = -1;my $nsw = -1;my $npv = -1;my $npq = -1;my $nsh = -1;my $nline = -1;my $title1 = 'Generic WEBFLOW data format '.$ARGV[0];my $title2;my $pbas = 100;my $freq = 60;my $format;my @data;my $bustype;my (@busidx,@busname,@ein,@pgen,@qgen,@pload,@qload,@bsh,@gsh);my (@swidx,@pvidx,@pqidx,@shidx);my (@busfr,@bustt,@rest,@reat,@susc,@ratio);my %busidxn;# -----------------------------------------------------------------------# check inputs# -----------------------------------------------------------------------$nargin = @ARGV;$nargin || die "Error: No input data file.\n";# -----------------------------------------------------------------------# 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 "\nWEBFLOW2PSAT converts WEBFLOW data files into PSAT data files.\n\n"; print "WEBFLOW2psat <options> fileinput <fileoutput>\n"; print " -v verbose\n"; print " -h print this help and exit\n\n"; print "Author: Juan Carlos Morataya\n"; print "Date: 13-Nov-2005\n"; print "Version: 1.0.0\n\n"; print "E-mail: jmorataya\@eegsa.net\n"; die "\n";}# -----------------------------------------------------------------------# define output file name (if necessary)# -----------------------------------------------------------------------if ($nargin == 1) { $ARGV[1] = $ARGV[0]; $ARGV[1] =~ s/^/d_/; $ARGV[1] =~ s/^d_d/d_/; $ARGV[1] =~ s/^d_d_/d_/; $ARGV[1] =~ s/[^a-zA-Z0-9_\.]/_/g; $ARGV[1] =~ s/\..*//; $ARGV[1] =~ s/^d__/d_/; $ARGV[1] = $ARGV[1] . ".m";} elsif ($nargin == 0) { die "Error: Input file name is missing.\n";}# -----------------------------------------------------------------------# open input data file# -----------------------------------------------------------------------print "Opening WEBFLOW data file \"$ARGV[0]\"...\n";carret();open(IN,$ARGV[0]) || die "cannot open $ARGV[0]: $!\n";# -----------------------------------------------------------------------# scan data file# -----------------------------------------------------------------------while (<IN>) { if (/^B/) { # matching data buses $nbus++; @data = split(/\s+/); $bustype = $data[0]; $busname[$nbus] = $data[1]; $busidx[$nbus] = $busname[$nbus]; $ein[$nbus] = $data[2]; $pgen[$nbus] = $data[3]; $qgen[$nbus] = $data[4]; $pload[$nbus] = $data[5]; $qload[$nbus] = $data[6]; $gsh[$nbus] = $data[7]; $bsh[$nbus] = $data[8]; if ($bustype eq "BS") { $nsw++; $swidx[$nsw] = $nbus; } elsif ($bustype eq "BV") { $npv++; $pvidx[$npv] = $nbus; } if ($pload[$nbus] != 0 || $qload[$nbus] != 0) { $npq++; $pqidx[$npq] = $nbus; } if ($bsh[$nbus] != 0) { $nsh++; $shidx[$nsh] = $nbus; } } if (/^L/) { # matching data lines $nline++; @data = split(/\s+/); $busfr[$nline] = $data[1]; $bustt[$nline] = $data[2]; $rest[$nline] = $data[3]; $reat[$nline] = $data[4]; $susc[$nline] = $data[6]; $ratio[$nline] = $data[7]; }}# -----------------------------------------------------------------------# close data file# -----------------------------------------------------------------------close(IN) || die "cannot close $ARGV[0]: $!\n";# -----------------------------------------------------------------------# open output data file# -----------------------------------------------------------------------print "Writing PSAT file \"$ARGV[1]\"...\n";carret();open(OUT,">$ARGV[1]") || die "cannot open $ARGV[1]: $!\n";# -----------------------------------------------------------------------# write output data file# -----------------------------------------------------------------------print OUT "% File generated by PSAT from WEBFLOW data file.\n";print OUT "% "."-" x 78 . "\n";print OUT "% Author: Juan Carlos Morataya\n";print OUT "% E-mail: jmorataya\@eegsa.net\n";print OUT "% "."-" x 78 . "\n";print OUT "% $title1\n\n";# -----------------------------------------------------------------------# write Bus.con# -----------------------------------------------------------------------$format = "%4d 1.00 %8.5f 0 1 1";$nbus >= 0 && print OUT "Bus.con = [ ...\n";for ($i = 0; $i <= $nbus-1; $i++) { printf OUT "$format;\n",$busidx[$i],$ein[$i];}$nbus >= 0 && printf OUT "$format];\n\n",$busidx[$i],$ein[$i];# -----------------------------------------------------------------------# write SW.con# -----------------------------------------------------------------------if ($nsw >= 0) { print OUT "SW.con = [ ...\n"; $format = "%4d $pbas 1 %8.5f 0 9.9900 -9.9900 1.1 0.9 %8.5f 1 "; $h = $swidx[0]; printf OUT "$format];\n\n", $busidx[$h],$ein[$h],$pgen[$h];} # -----------------------------------------------------------------------# write PV.con# -----------------------------------------------------------------------if ($npv >= 0) { print OUT "PV.con = [ ...\n"; $format = "%4d $pbas 1 " . "%10.5f " x 2 . " 9.9900 -9.9900 1.1 0.9 1"; for ($i = 0; $i <= $npv-1; $i++) { $h = $pvidx[$i]; printf OUT "$format;\n", $busidx[$h],$pgen[$h],$ein[$h]; } $h = $pvidx[$npv]; printf OUT "$format];\n\n",$busidx[$h],$pgen[$h],$ein[$h];}# -----------------------------------------------------------------------# write PQ.con# -----------------------------------------------------------------------if ($npq >= 0) { print OUT "PQ.con = [ ...\n"; $format = "%4d $pbas 1 " . "%10.5f " x 2 . " 1.1 0.9 1"; for ($i = 0; $i <= $npq-1; $i++) { $h = $pqidx[$i]; printf OUT "$format;\n", $busidx[$h],$pload[$h],$qload[$h]; } $h = $pqidx[$npq]; printf OUT "$format];\n\n",$busidx[$h],$pload[$h],$qload[$h];}# -----------------------------------------------------------------------# write Shunt.con# -----------------------------------------------------------------------if ($nsh >= 0) { print OUT "Shunt.con = [ ...\n"; $format = "%4d $pbas 1.00 60 " . "%8.5f " x 2 . ""; for ($i = 0; $i <= $nsh-1; $i++) { $h = $shidx[$i]; printf OUT "$format;\n", $busidx[$h],$gsh[$h],$bsh[$h]; } $h = $shidx[$nsh]; printf OUT "$format];\n\n",$busidx[$h],$gsh[$h],$bsh[$h];}# -----------------------------------------------------------------------# write Line.con# -----------------------------------------------------------------------if ($nline >= 0) { print OUT "Line.con = [ ...\n"; $format = "%4d %4d 100.00 1.0000 60 0 " . "%8.5f " x 5 . " 0 0 0 0 "; for ($i = 0; $i <= $nline-1; $i++) { if ($ratio[$i] != 0) { $k = 1; } else { $k = 0; } printf OUT "$format;\n", $busfr[$i],$bustt[$i],$k,$rest[$i], $reat[$i],$susc[$i],$ratio[$i]; } $i = $nline; if ($ratio[$i] != 0) { $k = 1; } else { $k = 0; } printf OUT "$format];\n\n", $busfr[$i],$bustt[$i],$k,$rest[$i], $reat[$i],$susc[$i],$ratio[$i];} # -----------------------------------------------------------------------# write bus names# -----------------------------------------------------------------------$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";# -----------------------------------------------------------------------# close output data file# -----------------------------------------------------------------------close(OUT) || die "cannot close $ARGV[1]: $!\n";print "Conversion completed.\n";# -----------------------------------------------------------------------# function for writing a separator# -----------------------------------------------------------------------sub carret { $verbose && print "-" x 50 . "\n";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -