#!/usr/bin/perl # extract lambda values from all.lamb of aa* directories # usage: extractLamb.pl [arguments] # arguments: total replicas; total exchange steps; phmd printing freq; dynamic steps per exchange; rexinfo file # $Nreplica = shift @ARGV; $Nxstep = shift @ARGV; $phmdpri = shift @ARGV; $Ndynstep = shift @ARGV; $rexinfo = shift @ARGV; $alllamb = shift @ARGV; $IfTaut = 0; print "Nreplica $Nreplica phmdpri $phmdpri Nxstep $Nxstep Ndynstep $Ndynstep \n"; # read final.lamb from all replicas and store them in vectors for ($ireplica = 1; $ireplica <= $Nreplica; $ireplica ++ ) { $dir = "aa$ireplica"; $lambfile= "$dir/$alllamb"; $ixstep = 1; open INP, "<$lambfile" or die ("can not open $lambfile") ; while () { @line = split(" ",$_); if ($line[0] !~ /\#/) { $idynstep = $line[0]; shift @line; $lamb[$ireplica][$ixstep][$idynstep] = join " ", @line; if ($idynstep == $Ndynstep){ $ixstep ++; } } else { $IfTaut = 1; if ($line[1] =~ /ires/) { $resfile = join " ", @line; } if ($line[1] =~ /itaut/) { $tautfile = join " ", @line; } } } close INP; } # read index file created by rexinfo.pl open INP, "<$rexinfo" or die ("can not open $rexinfo"); while () { if (/aa\d+/) { @line = split(" ",$_); $ixstep = $line[0]; $line[3] =~ s/aa(\d+)/\1/; $indx[$ixstep] = $line[3]; } } close INP; #create big lamb file using the index file $file = "$rexinfo.lambda"; open OUT, ">$file"; if ($IfTaut == 1) { print OUT "$resfile\n"; print OUT "$tautfile\n"; } for ($ixstep = 1; $ixstep <= $Nxstep; $ixstep ++) { $ireplica = $indx[$ixstep]; for ($idynstep = $phmdpri; $idynstep < $Ndynstep + 1; $idynstep += $phmdpri) { print OUT "$lamb[$ireplica][$ixstep][$idynstep]\n"; } } close OUT;