#!/usr/bin/perl # Author: Zbigniew Koziol. softquake@gmail.com # It sometime might be a good idea to run this script through a pipe, like # for instance, in this example: # ./my_log_parse.pl | sort -n # First, we want to have the listing of files in this directory, these files # that we will parse. In this particular case we want to find files # with names ending with "des.log" # We may use the following method to find these files: my $files = `/bin/ls -1 *des.log | /bin/sort -g`; # print $files; my (@myfiles) = split ("\n", $files); # now, array @myfiles contains a list of files that we want to parse. my $maxEl = 0; my $maxLH = 0; my $maxHH = 0; foreach my $file(@myfiles) { my (@myData); open(WAVE1, "<", "$file"); while(my $line=) { push @myData, $line; } close WAVE1; # Array @myData now contains the content of entire $file, line by line. # Let us now start parsing the data in array @myData. # This foreach loop must be very specific and written according to # your own needs. For 99.99978% the code of this loop will NOT work for you! # This code is just an EXAMPLE written for MY OWN particular needs. # # I want there to find laser wavelength and all energy levels # of electron and hole states in quantum well, and to save these values, # together with filename. # $noOfLines = @myData; $CondBandOffset = 0; $ValenceBandOffset = 0; for (my $i=0; $i<$noOfLines; $i++){ $line = @myData[$i];$line =~ s/\n//; if ($line =~ s/Wavelength// && $line =~ s/Effective Index//) { $i++; $line = @myData[$i];$line =~ s/\n//; ($x, $y, $wavelength, $z) = split(/\s+/,$line); } if ($line =~ s/Quantum Well Information//) { $i++;$i++;$line = @myData[$i];$line =~ s/\n//; if($line =~ s/Conduction Band Offset: //) { $line =~ s/ eV//; $CondBandOffset = $line; } $i++;$line = @myData[$i];$line =~ s/\n//; if($line =~ s/Valence Band Offset : //) { $line =~ s/ eV//; $ValenceBandOffset = $line; } $i++;$i++;$line = @myData[$i];$line =~ s/\n//; if($line =~ s/Electron subbands//) { $i++;$i++;$i++;$i++;$i++;$line = @myData[$i];$line =~ s/\n//; $ElectronSubbands = ''; $max1=0; while ($line ne "\n") { $line =~ s/\n//; $ElectronSubbands .= $line ."|"; $max1++; $i++;$line = @myData[$i]; } $ElectronSubbands =~ s/\|$//; $ElectronSubbands =~ s/ eV//g; $ElectronSubbands =~ s/ //g; if ($max1>$maxEl) { $maxEl = $max1; } $i++;$i++;$i++;$i++;$i++;$line = @myData[$i]; if ($line =~ s/Subband energies:/Subband energies:/) { $i++;$line = @myData[$i]; $LightHoleSubbands = ''; $max2=0; while ($line ne "\n") { $line =~ s/\n//; $LightHoleSubbands .= $line ."|"; $max2++; $i++;$line = @myData[$i]; } $LightHoleSubbands =~ s/\|$//; $LightHoleSubbands =~ s/ eV//g; $LightHoleSubbands =~ s/ //g; if ($max2>$maxLH) { $maxLH = $max2; } } $i++;$i++;$i++;$i++;$i++;$line = @myData[$i]; if ($line =~ s/Subband energies:/Subband energies:/) { $i++;$line = @myData[$i]; $HeavyHoleSubbands = ''; $max3=0; while ($line ne "\n") { $line =~ s/\n//; $HeavyHoleSubbands .= $line ."|"; $max3++; $i++;$line = @myData[$i]; } $HeavyHoleSubbands =~ s/\|$//; $HeavyHoleSubbands =~ s/ eV//g; $HeavyHoleSubbands =~ s/ //g; if ($max3>$maxHH) { $maxHH = $max3; } } } } } $file =~ s/\.log_des\.log//; $file =~ s/_/\./; $al = $file; # the following will print all quantum well energy levels: # print $al, "\t", $wavelength, "\t", $CondBandOffset, "\t", $ValenceBandOffset, "\t",$ElectronSubbands, "\t",$LightHoleSubbands, "\t",$HeavyHoleSubbands,"\n"; # the following will print 0-th energy levels # print $al, "\t", $wavelength, "\t", $CondBandOffset, "\t", $ValenceBandOffset, "\t", n_th_level(0, $ElectronSubbands, $LightHoleSubbands, $HeavyHoleSubbands), "\n"; # the following will print the maximum energy levels, only print $al, "\t", $wavelength, "\t", $CondBandOffset, "\t", $ValenceBandOffset, "\t", maximum_energy_levels($ElectronSubbands, $LightHoleSubbands, $HeavyHoleSubbands),"\n"; } # this will print the maximum number of energy levels # print "$maxEl\t$maxLH\t$maxHH\n"; sub n_th_level { my $level = shift; my $ElectronSubbands = shift; my $LightHoleSubbands = shift; my $HeavyHoleSubbands = shift; # we would like to have first maximum energy levels only. # for that, some math is needed: my (@e) = split(/\|/, $ElectronSubbands); my (@lh) = split(/\|/, $LightHoleSubbands); my (@hh) = split(/\|/, $HeavyHoleSubbands); my $maxElectronSubbands = @e[$level]; my $maxLightHoleSubbands = @lh[$level]; my $maxHeavyHoleSubbands = @hh[$level]; if ($maxElectronSubbands eq '') { $maxElectronSubbands = '?'; } if ($maxLightHoleSubbands eq '') { $maxLightHoleSubbands = '?'; } if ($maxHeavyHoleSubbands eq '') { $maxHeavyHoleSubbands = '?'; } return $maxElectronSubbands, "\t",$maxLightHoleSubbands, "\t",$maxHeavyHoleSubbands; } sub maximum_energy_levels { my $ElectronSubbands = shift; my $LightHoleSubbands = shift; my $HeavyHoleSubbands = shift; my (@e) = split(/\|/, $ElectronSubbands); my (@lh) = split(/\|/, $LightHoleSubbands); my (@hh) = split(/\|/, $HeavyHoleSubbands); $n = @e; my $maxElectronSubbands = @e[$n-1]; $n = @lh; my $maxLightHoleSubbands = @lh[$n-1]; $n = @hh; my $maxHeavyHoleSubbands = @hh[$n-1]; return $maxElectronSubbands, "\t",$maxLightHoleSubbands, "\t",$maxHeavyHoleSubbands; }