📄 digsilent2psat
字号:
#!/usr/bin/perl -w
# DIGSILENT2PSAT converts DIGSILENT data file into PSAT data file
#
# DIGSILENT2PSAT <OPTIONS> FILEINPUT <FILEOUTPUT>
#
# Author: Juan Carlos Morataya
# Date: 14-Oct-2005
# Update: 07-Mar-2006
# Version: 1.0.1
#
# E-mail: jc.morataya@ieee.org
#
use strict;
# -----------------------------------------------------------------------
# variable declaration
# -----------------------------------------------------------------------
my $nargin = 0;
my $verbose = 0;
my $helpmsg = 0;
my ($i,$h,$k,$w,$n,$m,$pb);
my $j = 0;
my $ntitle = -1;
my $nbus = -1;
my $nsw = -1;
my $npv = -1;
my $npq = -1;
my $nsh = -1;
my $ntw = -1;
my $nline = -1;
my $nsec = -1;
my $ncrd = 0;
my $nzo = 0;
my $nlpe = -1;
my $nttf = 0;
my $ndyn = -1;
my $nopq = -1;
my $nmn = -1;
my $nopv = -1;
my $ntwf = -1;
my $ngen = -1;
my $flglne = -1;
my $flgchk = -1;
my ($version,$msg,$crd,$mycard,
$format);
my ($swbus,$swsb,$swvs,$swqt,
$swqb,$swpg);
my ($title1,@title,$ver,$zn,$inomtr,
$inomtrh,$inomtrm,$inomtrl);
my $pbas = 100;
my (@data,@kvb,@kzonum,@kzoname,@loadtype,@bustype,
@busidx,@busname,@busvol,@qcap,@nmcrds,@add,
@kae,@pbas,@rt3a,@rt3b,@rt3c,@bshunt,@trfnum,
@twtname,@tpos,@bustw1,@bustw2,@bustw3,@lghtlne,
@linename,@r,@r12,@r23,@r13,@x,@x12,@x23,@x13,
@c,@kv1,@kv2,@kv3,@uktr,@uktrh,@uktrm,@uktrl,
@pcutr,@pcuth,@pcutm,@pcutl,@inomtr,@inomtrh,
@inomtrm,@inomtrl,@pbas2w,@kpu,@kqu);
my (@swidx,@pvidx,@pqbus,@pqname,@pqpl,@pqql,
@qshnt,@pshnt,@shbus,@symname,@pvbus,
@opmode,@pvvs,@pvpg,@pvqg,@pvqt,@pvqb,@symstt,
@xd,@xq,@xdsss,@rstr,@xdsat,@satur,@dline,
@typesec,@tr3wname,@gen,@busfr,@bustt,@symtype,
@pvsb);
my (@rest,@reat,@susc,@rate,@phs,@phrg,@ttr,@ttt);
my (%kvbase,%pbase,%crdord,%busidxn,%kzo,%rest,
%reat, %susc,%lnerate,%bsfr,%bstt,%pqidx,
%qsh,%psh,%pvidx,%pvqb,%r12,%x12,%r23,%x23,
%r13,%x13,%rt3a,%rt3b,%rt3c,%tpscln,%tp,%lght,
%symtn,%phsf,%ktep,%kteq,%pqtype);
# -----------------------------------------------------------------------
# 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 "\nDIGSILENT2PSAT converts DIGSILENT data files into PSAT data files.\n\n";
print "DIGSILENT2psat <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: 14-Oct-2005\n";
print "Update: 07-Mar-2006\n";
print "Version: 1.0.1\n\n";
print "E-mail: jc.morataya\@ieee.org\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";
}
# -----------------------------------------------------------------------
# checking for data cards in input data file
# -----------------------------------------------------------------------
print "Opening DIGSILENT data file \"$ARGV[0]\"...\n";
carret();
print "Checking input data cards...\n";
open(IN,$ARGV[0]) || die "cannot open $ARGV[0]: $!\n";
open(SAL,">EXIT.txt") || die "cannot open $ARGV[0]: $!\n";
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
$_ =~ s/\$//g;
my $semicolon = index "$_" , ';';
my $blankspace = index "$_", , '!\d';
my $crds = substr "$_",0,$blankspace;
my $nmcrds = substr "$_",0,$semicolon;
if ($_ =~ /^\w+/) {
$ncrd++;
$nmcrds[$ncrd] = substr "$_",0,$semicolon;
$crdord{$ncrd} = $crds;
$crdord{$nmcrds} = $crds;
}
}
close(IN) || die "cannot close $ARGV[0]: $!\n";
# -----------------------------------------------------------------------
# open input data file
# -----------------------------------------------------------------------
print "Scanning DIGSILENT data file \"$ARGV[0]\"...\n";
carret();
open(IN,$ARGV[0]) || die "cannot open $ARGV[0]: $!\n";
# -----------------------------------------------------------------------
# scan input data file
# -----------------------------------------------------------------------
$_ = <IN>; # discard first line
# read comments and case information
while (<IN>) {
$_ =~ s/^\*//g;
next if !/\d+/;
last if /^\$\$/;
$ntitle++;
$title[$ntitle] = $_;
$title[$ntitle] =~ s/\s+/+/g;
$title[$ntitle] =~ s/\+/ /g;
}
for ($n = 1; $n <= $ncrd; $n++) {
# <$$General> data card
$j = matching("General");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$Classes> data card
$j = matching("Classes");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ChaRef> data card
$j = matching("ChaRef");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ChaVec> data card
$j = matching("ChaVec");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ElmAsm> data card
$j = matching("ElmAsm");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
}
}
# <$$ElmCoup> data card
$j = matching("ElmCoup");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ElmComp> data card
$j = matching("ElmComp");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ElmDsl> data card
$j = matching("ElmDsl");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
}
}
# <$$ElmLne> data card
# line element data
$j = matching("ElmLne");
if ($j == $n && $flgchk < 0) {
$crd = $n;
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$nline++;
$linename[$nline] = assign("ElmLne",'Name',1);
$busfr[$nline] = assign("ElmLne",'Station1',);
$bustt[$nline] = assign("ElmLne",'Station2',);
$lghtlne[$nline] = assign("ElmLne",'dline',1);
$pbase{$linename[$nline]} = 100;
$lght{$linename[$nline]} = $lghtlne[$nline];
unless ($busfr[$nline] || $bustt[$nline]) { $flgchk++; }
}
}
# <$$ElmLnesec> data card
# line section data
$j = matching("ElmLnesec");
if ($j == $n && $flgchk < 0) {
$flglne++;
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$nsec++;
$linename[$nsec] = assign("ElmLnesec",'fold_id',1);
$typesec[$nsec] = assign("ElmLnesec",'typ_id',1)."-".$nsec;
$dline[$nsec] = assign("ElmLnesec",'dline',1);
$tpscln{$typesec[$nsec]} = $linename[$nsec];
}
print ""."$nsec"." transmission line sections founded...\n";
print "WARNING: \"ElmLnesec\" data card will be ignored ...\n";
}
# <$$ElmLod> data card
# load element data
$j = matching("ElmLod");
if ($j == $n && $flgchk < 0) {
$crd = $n;
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$npq++;
$pqname[$npq] = assign("ElmLod",'Name',1);
$loadtype[$npq] = assign("ElmLod",'typ_id',1);
$pqbus[$npq] = assign("ElmLod",'Station1',);
$pqidx{$pqname[$npq]} = $pqbus[$npq];
$pqtype{$pqidx{$pqname[$npq]}} = $loadtype[$npq];
unless ($pqbus[$npq]) { $flgchk++; }
}
}
#<$$ElmRelay> data card
$j = matching("ElmRelay");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
}
}
# <$$ElmShnt> data card
# shunt element data
$j = matching("ElmShnt");
if ($j == $n && $flgchk < 0) {
$crd = $n;
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$nsh++;
$shbus[$nsh] = assign("ElmShnt",'Station1',);
$qshnt[$nsh] = assign("ElmShnt",'qcapn',0)/$pbas;
$pshnt[$nsh] = 0;
unless ($shbus[$nsh]) { $flgchk++; }
}
}
# <$$ElmSym> data card
# sychronous machine element data
$j = matching("ElmSym");
if ($j == $n && $flgchk < 0) {
$crd = $n;
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$npv++;
$symname[$npv] = assign("ElmSym",'Name',1);
$symtype[$npv] = assign("ElmSym",'typ_id',1);
$pvbus[$npv] = assign("ElmSym",'Station1',);
$pvidx{$symname[$npv]} = $pvbus[$npv];
$symtn{$symname[$npv]} = $symtype[$npv];
unless ($pvbus[$npv]) { $flgchk++; }
}
}
# <$$ElmTerm> data card
# terminal element data
$j = matching("ElmTerm");
if ($j == $n && $flgchk < 0) {
while (<IN>) {
next if /^\*+/;
next if /^\*+\s+\w+/;
next if /^.$/;
last if /^\$\$/;
@data = mysplit($_);
$nbus++;
$busidx[$nbus] = assign("ElmTerm",'No',1);
$busname[$nbus] = assign("ElmTerm",'Name',$busidx[$nbus]);
$kvb[$nbus] = assign("ElmTerm",'uknom',1.00);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -