抽出部分网络数据程序

返回

use strict; my(%t,$fref,$n,$n1,$n2,$start,@ee,@fld,@nodes); $t{file} = "start_end.txt"; $$fref{inputfile} = "s.txt"; $$fref{outputfile} = "s_out.txt"; # Read starting and ending node open(IN,"$t{file}") or die "Can't open the file $t{file}\n"; while (<IN>) { @fld = split; if ( /^S\s/ ) { $start = $fld[1]; $$fref{snode} = $start; } elsif ( /^E\s/ ) { for $n ( 1 .. $#fld ) { push(@ee,$fld[$n]); } $$fref{enode} = $ee[0]; } } close(IN); # Start $$fref{opp} = ''; for $n (@ee) { $$fref{opp} = $$fref{opp} . ' ' . $n; } @{ $$fref{nodes} } = ($start); $$fref{node} = $start; @{ $$fref{br} } = (); foreach $n (@{ $$fref{nodes} }) { $$fref{parent} = $n; ($fref) = findnode($fref); @{ $$fref{nodes} } = split(' ',$$fref{node}); } # Print out result. ($fref) = print_N($fref); # Print out results sub print_N { my($fref) = @_; my(%t,@fld); open(IN,"$$fref{inputfile}") or die "Can't open file $$fref{inputfile}\n"; open(OUT,">$$fref{outputfile}\n"); print OUT '********************************************************',"\n"; print OUT 'The original nodes.',"\n"; print OUT '********************************************************',"\n"; while (<IN>) { if (/^N\s/){ print OUT $_; } } close(IN); print OUT '********************************************************',"\n"; print OUT 'Starting node is ',$$fref{snode},"\n"; print OUT 'Ending node is ',$$fref{enode},"\n"; print OUT '********************************************************',"\n"; print OUT 'The selected nodes.',"\n"; print OUT '********************************************************',"\n"; open(IN,"$$fref{inputfile}") or die "Can't open file $$fref{inputfile}\n"; while (<IN>) { @fld = split; if (/^N\s/){ if ( $$fref{node} =~ /$fld[1]/ ) { print OUT $_; } } } close(IN); print OUT '********************************************************',"\n"; close(OUT); return($fref); } # subroutine sub findnode { my($fref) = @_; my(%t,@fld,$n1,$n2,$br); open(IN,"$$fref{inputfile}") or die "Can't open file $$fref{inputfile}\n"; while (<IN>) { @fld = split; if ( /^T\s/ or /^X\s/ ) { @fld=split; $br = $fld[1]; # Branch if ( $fld[2] eq 'Z' ) { $n1 = sprintf("%07d",$fld[3]); $n2 = sprintf("%07d",$fld[4]); } else { $n1 = sprintf("%07d",$fld[2]); $n2 = sprintf("%07d",$fld[3]); } if ( $n1 eq $$fref{parent} && (!($$fref{opp} =~ /$n2/)) && (!($$fref{node} =~ /$n2/)) ) { $$fref{node} = $$fref{node} . ' ' . $n2; push(@{ $$fref{br} },$br); } elsif ( $n2 eq $$fref{parent} && (!($$fref{opp} =~ /$n1/)) && (!($$fref{node} =~ /$n1/)) ) { $$fref{node} = $$fref{node} . ' ' . $n1; push(@{ $$fref{br} },$br); } } } close(IN); return($fref); }
运行结果文件 ******************************************************** The original nodes. ******************************************************** N 3010 1.01 8.32 0.0 0.44 0.088 0.0 N 3020 1.01 4.55 0.0 0.20 0.040 0.0 N 3030 1.01 3.10 0.0 0.13 0.026 0.0 N 3040 1.01 3.49 0.0 0.10 0.020 0.0 N 3050 1.01 1.78 0.0 0.10 0.020 0.0 N 3060 1.01 2.76 0.0 0.77 0.154 0.0 N 3070 1.01 1.20 0.0 0.06 0.012 0.0 N 3080 1.01 2.17 0.0 0.09 0.018 0.0 N 3090 1.01 4.10 0.0 0.69 0.138 0.0 N 3100 1.01 5.01 0.0 0.28 0.056 0.0 N 3110 1.01 3.06 0.0 0.12 0.024 0.0 N 3120 1.01 4.70 0.0 0.31 0.062 0.0 N 3130 1.01 6.63 0.0 0.24 0.048 0.0 N 3140 1.01 2.21 0.0 0.09 0.018 0.0 N 3150 1.01 3.80 0.0 0.14 0.028 0.0 N 3160 1.01 3.46 0.0 0.20 0.040 0.0 N 3170 1.01 2.86 0.0 0.01 0.002 0.0 N 3180 1.01 3.30 0.0 0.14 0.028 0.0 N 3190 1.01 1.82 0.0 0.10 0.02 0.0 N 3200 1.01 4.63 0.0 0.19 0.038 0.0 N 3210 1.01 1.02 0.0 0.06 0.012 0.0 N 3220 1.01 1.50 0.0 0.07 0.014 0.0 N 3230 1.01 7.98 0.0 0.24 0.048 0.0 N 3240 1.01 0.75 0.0 0.0 0.0 0.0 N 3250 1.01 0.38 0.0 0.0 0.0 0.0 N 3260 1.01 1.96 0.0 0.03 0.006 0.0 N 3270 1.01 2.58 0.0 0.08 0.016 0.0 N 3280 1.01 5.25 0.0 0.26 0.052 0.0 N 3290 1.01 3.31 0.0 0.10 0.02 0.0 N 3300 1.01 2.78 0.0 0.11 0.022 0.0 N 1050 0.0 0.0 0.0 1.14 0.228 0.0 N 1070 0.0 0.0 0.0 0.94 0.188 0.0 N 1090 0.0 0.0 0.0 0.60 0.120 0.0 N 1140 0.0 0.0 0.0 0.88 0.176 0.0 N 1170 0.0 0.0 0.0 1.36 0.272 0.0 N 1200 0.0 0.0 0.0 0.87 0.174 0.0 N 1210 0.0 0.0 0.0 0.56 0.112 0.0 N 1230 0.0 0.0 0.0 2.88 0.576 0.2 N 1250 0.0 0.0 0.0 6.62 1.324 2.2 N 1260 0.0 0.0 0.0 6.56 1.312 1.6 N 1280 0.0 0.0 0.0 0.15 0.030 0.0 N 1300 0.0 0.0 0.0 5.51 1.102 1.0 N 1320 0.0 0.0 0.0 2.69 0.538 0.4 N 1350 0.0 0.0 0.0 4.56 0.912 0.8 N 1370 0.0 0.0 0.0 2.74 0.548 0.4 N 1380 0.0 0.0 0.0 1.41 0.282 0.0 N 1410 0.0 0.0 0.0 4.34 0.868 0.5 N 1430 0.0 0.0 0.0 0.66 0.132 0.0 N 1440 0.0 0.0 0.0 0.16 0.032 0.0 N 1550 0.0 0.0 0.0 2.19 0.438 0.2 N 2010 0.0 0.0 0.0 4.94 0.988 0.8 N 2020 0.0 0.0 0.0 4.73 0.946 0.7 N 2030 0.0 0.0 0.0 5.05 1.01 0.9 N 2040 0.0 0.0 0.0 1.83 0.366 0.0 N 2080 0.0 0.0 0.0 1.58 0.316 0.0 N 2090 0.0 0.0 0.0 3.03 0.606 0.3 N 2100 0.0 0.0 0.0 3.97 0.794 0.5 N 2230 0.0 0.0 0.0 6.87 1.374 0.9 N 2250 0.0 0.0 0.0 1.87 0.374 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0.0 0.0 0.0 0.0 0.0 0.0 N 1510 0.0 0.0 0.0 0.0 0.0 0.0 N 1520 0.0 0.0 0.0 0.0 0.0 0.0 N 1530 0.0 0.0 0.0 0.0 0.0 0.0 N 1540 0.0 0.0 0.0 0.0 0.0 0.0 N 2050 0.0 0.0 0.0 0.0 0.0 0.0 N 2060 0.0 0.0 0.0 0.0 0.0 0.0 N 2070 0.0 0.0 0.0 0.0 0.0 0.0 N 2110 0.0 0.0 0.0 0.0 0.0 0.0 N 2120 0.0 0.0 0.0 0.0 0.0 0.0 N 2130 0.0 0.0 0.0 0.0 0.0 0.0 N 2140 0.0 0.0 0.0 0.0 0.0 0.0 N 2150 0.0 0.0 0.0 0.0 0.0 0.0 N 2160 0.0 0.0 0.0 0.0 0.0 0.0 N 2170 0.0 0.0 0.0 0.0 0.0 0.0 N 2180 0.0 0.0 0.0 0.0 0.0 0.0 N 2190 0.0 0.0 0.0 0.0 0.0 0.0 N 2200 0.0 0.0 0.0 0.0 0.0 0.0 N 2210 0.0 0.0 0.0 0.0 0.0 0.0 N 2220 0.0 0.0 0.0 0.0 0.0 0.0 N 2240 0.0 0.0 0.0 0.0 0.0 0.0 ******************************************************** Starting node is 0003020 Ending node is 0001220 ******************************************************** The selected nodes. ******************************************************** N 3010 1.01 8.32 0.0 0.44 0.088 0.0 N 3020 1.01 4.55 0.0 0.20 0.040 0.0 N 3030 1.01 3.10 0.0 0.13 0.026 0.0 N 3040 1.01 3.49 0.0 0.10 0.020 0.0 N 3050 1.01 1.78 0.0 0.10 0.020 0.0 N 3060 1.01 2.76 0.0 0.77 0.154 0.0 N 3070 1.01 1.20 0.0 0.06 0.012 0.0 N 3080 1.01 2.17 0.0 0.09 0.018 0.0 N 3090 1.01 4.10 0.0 0.69 0.138 0.0 N 3100 1.01 5.01 0.0 0.28 0.056 0.0 N 1050 0.0 0.0 0.0 1.14 0.228 0.0 N 1070 0.0 0.0 0.0 0.94 0.188 0.0 N 1090 0.0 0.0 0.0 0.60 0.120 0.0 N 1140 0.0 0.0 0.0 0.88 0.176 0.0 N 1170 0.0 0.0 0.0 1.36 0.272 0.0 N 1200 0.0 0.0 0.0 0.87 0.174 0.0 N 1210 0.0 0.0 0.0 0.56 0.112 0.0 N 2010 0.0 0.0 0.0 4.94 0.988 0.8 N 2020 0.0 0.0 0.0 4.73 0.946 0.7 N 2030 0.0 0.0 0.0 5.05 1.01 0.9 N 2040 0.0 0.0 0.0 1.83 0.366 0.0 N 2080 0.0 0.0 0.0 1.58 0.316 0.0 N 2090 0.0 0.0 0.0 3.03 0.606 0.3 N 2100 0.0 0.0 0.0 3.97 0.794 0.5 N 1010 0.0 0.0 0.0 0.0 0.0 0.0 N 1020 0.0 0.0 0.0 0.0 0.0 0.0 N 1030 0.0 0.0 0.0 0.0 0.0 0.0 N 1040 0.0 0.0 0.0 0.0 0.0 0.0 N 1060 0.0 0.0 0.0 0.0 0.0 0.0 N 1080 0.0 0.0 0.0 0.0 0.0 0.0 N 1100 0.0 0.0 0.0 0.0 0.0 0.0 N 1110 0.0 0.0 0.0 0.0 0.0 0.0 N 1120 0.0 0.0 0.0 0.0 0.0 0.0 N 1130 0.0 0.0 0.0 0.0 0.0 0.0 N 1150 0.0 0.0 0.0 0.0 0.0 0.0 N 1160 0.0 0.0 0.0 0.0 0.0 0.0 N 1180 0.0 0.0 0.0 0.0 0.0 0.0 N 1190 0.0 0.0 0.0 0.0 0.0 0.0 N 2050 0.0 0.0 0.0 0.0 0.0 0.0 N 2060 0.0 0.0 0.0 0.0 0.0 0.0 N 2070 0.0 0.0 0.0 0.0 0.0 0.0 ********************************************************
filename:start_end.txt C S:start node; E:end node S 0003020 E 0001220
返回