File indexing completed on 2024-04-06 11:56:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 use POSIX;
0019
0020 $inFile = "undefined";
0021 $thisGen = 1;
0022 $totalGen = 0;
0023
0024
0025 while (@ARGV) {
0026 $arg = shift(@ARGV);
0027 if ($arg =~ /\A-/) {
0028 if ($arg =~ "h") {
0029 $helpwanted = 1;
0030 }
0031 elsif ($arg =~ "d") {
0032 $localdir = 1;
0033 }
0034 elsif ($arg =~ "u") {
0035 $updateDb = 1;
0036 }
0037 $optionstring = "$optionstring$arg";
0038 }
0039 else {
0040 $i = $i + 1;
0041 if ($i eq 1) {
0042 $inFile = $arg;
0043 }
0044 elsif ($i eq 2) {
0045 $thisGen = $arg;
0046 }
0047 elsif ($i eq 3) {
0048 $totalGen = $arg;
0049 }
0050 }
0051 }
0052
0053 if ($totalGen <= 0) {
0054 print "Insufficient information given\n";
0055 exit 1;
0056 }
0057
0058 if ($thisGen <= 0) {
0059 print "mps_split: zero thisGen --> exit\n";
0060 exit 1;
0061 }
0062 if ($thisGen > $totalGen) {
0063 print "mps_split: thisGen gt totalGen, $thisGen gt $totalGen --> exit\n";
0064 exit 1;
0065 }
0066
0067
0068 open INFILE,"$inFile";
0069 undef $/;
0070 $body = <INFILE>;
0071 close INFILE;
0072 $/ = "\n";
0073
0074
0075 @LINESALL = split "\n",$body;
0076
0077 my @LINES;
0078 foreach my $line (@LINESALL) {
0079 unless ($line =~ /^\s*
0080 push (@LINES, $line);
0081 }
0082 }
0083
0084
0085 $ninfi = $#LINES + 1;
0086
0087 my $poolDef = "";
0088 if ($LINES[0] =~ /^CastorPool=/) {
0089 $poolDef = $LINES[0];
0090 $ninfi = $ninfi - 1;
0091 }
0092
0093
0094 $chunkSize = $ninfi / $totalGen;
0095
0096 $startId =floor( ($thisGen - 1) * $chunkSize ) + 1;
0097 $endId = floor( $thisGen * $chunkSize);
0098
0099 if ($thisGen == 1) {
0100 $startId = 1;
0101 }
0102 if ($thisGen == $totalGen) {
0103 $endId = $ninfi;
0104 }
0105 if ($poolDef ne "") {
0106 $startId = $startId + 1;
0107 $endId = $endId + 1;
0108 }
0109
0110
0111
0112 if ($endId < $startId) {
0113 print "Invalid interval, startId=$startId, endID=$endId\n";
0114 print "ninfi was $#infi\n";
0115 exit 2;
0116 }
0117
0118 print "$poolDef\n" if ($poolDef ne "");
0119
0120
0121 for ($i = $startId; $i <= $endId; ++$i) {
0122 print "@LINES[$i-1]\n";
0123 }