# Class for parsing cmc.out # # Written by k-fleak # class ParseCMCout def initialize(filename) @cmcOut = open(filename, "r") parseCMCout end def getNumAtomMCcell @numAtomMCcell end def getPosition @position end def getAveEnergy @eAveMCcell end def getCorrelation @corr end private def parseCMCout flagArray = [0, 0, 0] @corr = Array.new @position = Array.new @cmcOut.each do |line| case line when /correlation/ flagArray[0] = 1 when /Averages/ flagArray[0] = 0 flagArray[1] = 1 when /Position/ flagArray[1] = 0 flagArray[2] = 1 end if flagArray[0] == 1 then corrTmp = Array.new unless line.strip.empty? or /correlation/ =~ line or /-----/ =~ line then lineArr = line.strip.split(/:/) @corr.push([lineArr[0].strip, lineArr[1].strip]) end end if flagArray[1] == 1 then if /eV/ =~ line then lineArr = line.strip.split @eAveMCcell = lineArr[4].to_f end end if flagArray[2] == 1 then unless line.strip.empty? or /Position/ =~ line or /-----/ =~ line then lineArr = line.strip.split @position.push(lineArr) end end end @numAtomMCcell = @position.size end end pc = ParseCMCout.new("cmc.out")