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

📄 inptc12psat

📁 电力系统分析计算程序
💻
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl -w# INPTC12PSAT converts INPTC1 data file into PSAT data file## INPTC12PSAT <OPTIONS> FILEINPUT <FILEOUTPUT>## Author:  Federico Milano# Date:    16-Apr-2006# Version: 1.0.0# # E-mail:    fmilano@thunderbox.uwaterloo.ca# Web-site:  http://thunderbox.uwaterloo.ca/~fmilanouse strict;# -----------------------------------------------------------------------# variable declaration# -----------------------------------------------------------------------my $nargin = 0;my $verbose = 0;my $helpmsg = 0;my $colasadd = 0;my $addfile = " ";my ($i,$h);my $nbus = -1;my $nsw = -1;my $npv = -1;my $npq = -1;my $nsh = -1;my $nsup = -1;my $nline = -1;my $ntitle = -1;my $narea = -1;my $nregion = 0;my @title;my $format;my $busty;my ($tempcode,$tempto,$tempfr);my $vx = 0;my (@vnomdef,@vmindef,@vmaxdef);my (%buscode,%linecode,%region);my $pvbus = "yyyy";my $swbus = "xxxx";my (@busname,@busvol,@pgen,@qgen,@vmin,@vmax,@pload,@qload,@qmax,@qmin,@vnom,@busreg);my (@swidx,@pvidx,@pqidx);my (@busfr,@busto,@rline,@xline,@bline,@kline,@vline,@mline,@iline);my (@shidx,@ssh,@qsh,@vsh);my (@supidx,@supsn,@suppmax,@suppmin,@supqmax,@supqmin,@supc0,@supc1,@supc2);my (@areanum,@areaslack,@areaexp,@areatol);# -----------------------------------------------------------------------# 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;}    if ($ARGV[0] =~ /a/) {	$colasadd = 1;	$addfile = $ARGV[1];	@ARGV = @ARGV[0, 2 .. $#ARGV];  	$nargin--;    }    shift(@ARGV);    $nargin--;    if ($nargin == 0) { 	last;    }}$title[0] = 'Generic INPTC1 data format ' . $ARGV[0];# -----------------------------------------------------------------------# help (if requested)# -----------------------------------------------------------------------if ($helpmsg) {    print "\nINPTC12PSAT converts INPTC1 data files into PSAT data files.\n\n";    print "inptc12psat <options> fileinput <fileoutput>\n";    print "  -v   verbose\n";    print "  -h   print this help and exit\n\n";    print "Date:     16-Apr-2006\n";    print "Version:  1.0.0\n\n";    print "Author:   Federico Milano\n";    print "E-mail:   fmilano\@thunderbox.uwaterloo.ca\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 input data file# -----------------------------------------------------------------------print "Opening INPTC1 data file \"$ARGV[0]\"...\n";open(IN,$ARGV[0]) || die "cannot open $ARGV[0]: $!\n";# -----------------------------------------------------------------------# read data# -----------------------------------------------------------------------while (<IN>) {    chomp;    $busty = substr($_,79,1);    if ($busty eq 'O') { # Kind of data	# not used    } elsif ($busty eq 'C') { # Data description	$ntitle++;	$title[$ntitle] = substr($_,0,78);    } elsif ($busty eq 'F') { # End of data	last;    } elsif ($busty eq '*') { # Comment	# nothing to do...    } elsif ($busty eq '#') { # Comment (not documented)	# nothing to do...    } elsif ($busty eq 'Z') { # Voltage Definition	if (/^VNOM/) {	    @vnomdef = split /\s+/;	} elsif (/^VMIN/) {	    @vmindef = split /\s+/;	} elsif (/^VMAX/) {	    @vmaxdef = split /\s+/;	}    } elsif ($busty eq 'W') { # DC connection	# not supported yet ...    } elsif ($busty eq 'N') { # Bus 	$nbus++;	$busname[$nbus] = getname($_,60,75) . substr($_,0,5);	$tempcode = getcode($_,0,5);	$buscode{$tempcode} = $nbus;	$vx = substr($_,4,1);	if (!$region{substr($_,3,1)}) { 	    $nregion++;	    $region{substr($_,3,1)} = $nregion;	} 	$busreg[$nbus] = $region{substr($_,3,1)};	$vnom[$nbus] = $vnomdef[$vx];	$busvol[$nbus] = getval($_,47,51,$vnomdef[$vx]);	$vmin[$nbus] = getval($_,53,55,$vmindef[$vx]);	$vmax[$nbus] = getval($_,57,59,$vmaxdef[$vx]);	# If the additional data file is missing, voltage rates can be wrong.	# The following is an euristic method to fix voltage rates	if (($busvol[$nbus]/$vnom[$nbus] < 0.95 ||	     $busvol[$nbus]/$vnom[$nbus] > 1.05) &&	    $vnom[$nbus] < 150) { 	    $vnom[$nbus] = round($busvol[$nbus]);	}	#$busvol[$nbus] /= $vnom[$nbus];	$vmin[$nbus] /= $vnomdef[$vx];	$vmax[$nbus] /= $vnomdef[$vx];	$pgen[$nbus] = getval($_,13,19,0)/100;	$qgen[$nbus] = getval($_,37,41,0)/100;	$qmax[$nbus] = 0;	$qmin[$nbus] = 0;	if ($pgen[$nbus] != 0 || $qgen[$nbus] != 0) {	    $npq++;		    $pload[$npq] = $pgen[$nbus];	    $qload[$npq] = $qgen[$nbus];	    $pqidx[$npq] = $nbus;	}	if (substr($_,22,1) eq 'T') {	    $nsw++;	    $swidx[$nsw] = $nbus;	    $swbus = $tempcode;	    $pgen[$nbus] = 0;	}	if (substr($_,44,1) eq 'T') {	    $npv++;	    $pvidx[$npv] = $nbus;	    $pvbus = $tempcode;	}    } elsif ($busty eq 'I') { # Hydro-electric generator 	$tempcode = getcode($_,0,5);	if ($pvbus ne $tempcode && $swbus ne $tempcode) {	    $npv++;	    $pvidx[$npv] = $nbus;	    $pvbus = $tempcode;	    if ($pqidx[$npq] == $nbus && $pgen[$nbus] <= 0) { $npq--; }	    $pgen[$nbus] = getval($_,15,19,0)/100;	    $qmin[$nbus] = -getval($_,43,46,0)/100;	    $qmax[$nbus] = abs(getval($_,48,51,0)/100);	} elsif ($pvbus eq $tempcode) {	    $pgen[$nbus] += getval($_,15,19,0)/100;	    	    $qmin[$nbus] += -getval($_,43,46,0)/100;	    $qmax[$nbus] += abs(getval($_,48,51,0)/100);	} elsif ($swbus eq $tempcode) {	    $pgen[$nbus] += getval($_,15,19,0)/100;	    	    	}	$nsup++;	$supidx[$nsup] = $buscode{$tempcode};	$supsn[$nsup] = abs(getval($_,31,34,-100));	$suppmax[$nsup] = abs(getval($_,26,29,0)/$supsn[$nsup]);	$suppmin[$nsup] = -getval($_,21,24,0)/$supsn[$nsup];	$supqmax[$nsup] = abs(getval($_,48,51,0)/$supsn[$nsup]);	$supqmin[$nsup] = -getval($_,43,46,0)/$supsn[$nsup];	$supc0[$nsup] = 0;	$supc1[$nsup] = 0;	$supc2[$nsup] = 0;    } elsif ($busty eq 'E') { # Thermo-electric generator 	$tempcode = getcode($_,0,5);	if ($pvbus ne $tempcode && $swbus ne $tempcode) {	    $npv++;	    $pvidx[$npv] = $nbus;	    $pvbus = $tempcode;	    if ($pqidx[$npq] == $nbus && $pgen[$nbus] <= 0) { $npq--; }	    $pgen[$nbus] = getval($_,15,19,0)/100;	    $qmin[$nbus] = -getval($_,43,46,0)/100;	    $qmax[$nbus] = abs(getval($_,48,51,0)/100);	} elsif ($pvbus eq $tempcode) {	    $pgen[$nbus] += getval($_,15,19,0)/100;	    	    $qmin[$nbus] += -getval($_,43,46,0)/100;	    $qmax[$nbus] += abs(getval($_,48,51,0)/100);	} elsif ($swbus eq $tempcode) {	    $pgen[$nbus] += getval($_,15,19,0)/100;	    	    	}	$nsup++;	$supidx[$nsup] = $buscode{$tempcode};	$supsn[$nsup] = abs(getval($_,31,34,-100));	$suppmax[$nsup] = abs(getval($_,26,29,0)/$supsn[$nsup]);	$suppmin[$nsup] = -getval($_,21,24,0)/$supsn[$nsup];	$supqmax[$nsup] = abs(getval($_,48,51,0)/$supsn[$nsup]);	$supqmin[$nsup] = -getval($_,43,46,0)/$supsn[$nsup];	# prices are given in Euros	$supc0[$nsup] = getval($_,9,13,0)*getval($_,53,59,0)/1936.27;	$supc1[$nsup] = getval($_,9,13,0)*getval($_,61,66,0)/1936.27;	$supc2[$nsup] = getval($_,9,13,0)*getval($_,68,74,0)/1936.27;    } elsif ($busty eq 'S') { # Synchronous compensator 	$tempcode = getcode($_,0,5);	if ($pvbus ne $tempcode && $swbus ne $tempcode) {	    $npv++;	    $pvidx[$npv] = $nbus;	    $pvbus = $tempcode;	    if ($pqidx[$npq] == $nbus && $pgen[$nbus] <= 0) { $npq--; }	}    } elsif ($busty eq 'Q') { # Shunt condenser	$tempcode = getcode($_,0,5);	$nsh++;	$shidx[$nsh] = $buscode{$tempcode};	$ssh[$nsh] = -getval($_,47,51,-100); 	$qsh[$nsh] = -getval($_,37,41,0)/$ssh[$nsh]; 	$vsh[$nsh] = getval($_,43,46,$vnomdef[substr($_,4,1)]);     } elsif ($busty eq 'L') { # Transmission line 	$tempfr = getcode($_,0,5);	$tempto = getcode($_,6,5);	if ($linecode{$tempfr . $tempto}) { next; }	$nline++;	$vx = substr($_,4,1);	$vline[$nline] = substr($_,4,1);	$busfr[$nline] = $tempfr;	$busto[$nline] = $tempto;	$linecode{$tempto . $tempfr} = $nline+1;	$kline[$nline] = 0;	$mline[$nline] = 0;	#$lline[$nline] = getval($_,29,35,1); # line length	$rline[$nline] = 100*getval($_,45,51,0)/$vnomdef[$vx]/$vnomdef[$vx];	$xline[$nline] = 100*getval($_,52,59,0)/$vnomdef[$vx]/$vnomdef[$vx];	$bline[$nline] = $vnomdef[$vx]*$vnomdef[$vx]*getval($_,60,66,0)/100000000;	#$rline[$nline] = getval($_,45,51,0)/$lline[$nline];	#$xline[$nline] = getval($_,52,59,0)/$lline[$nline];	#$bline[$nline] = getval($_,60,66,0)/1000000/$lline[$nline];	$iline[$nline] = sqrt(3)*$vnomdef[$vx]*getval($_,23,27,0)/100000;	#$npar[$nline] = getval($_,13,13,0);    } elsif ($busty eq 'T') { # Transformer 	$tempfr = getcode($_,0,5);	$tempto = getcode($_,6,5);	if ($linecode{$tempfr . $tempto}) { next; }	$nline++;	$vx = substr($_,4,1);	if (substr($_,10,1) < $vx) { 

⌨️ 快捷键说明

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