#!/usr/local/bin/ruby # read from data file and output igortxt # version 2004.12.13 def fmlwt(fml) #weight and formula (weight) wt={} IO::foreach("formula.dat") do |l| if l=~/([A-Z][a-z]?)\s+([\d\.]*)/ wt[$1]=$2.to_f end end fw=0 while fml.size>0 break unless m=/([A-Z][a-z]?)([\d\.]*)/.match(fml) aw=wt[m[1]] if m[2]=="" then an=1 else an=m[2].to_f end fw+=an*aw fml=m.post_match end if fw==0 then fw=1 end return fw end def wrap(t) w=[-5.72528e-07, 2.06049e-06, -18.4991] return w[0]+w[1]/(t-w[2]) end def ohp(t) w=[-4.26914e-07,9.82091e-08,-0.126265] return w[0]+w[1]/(t-w[2]) end # main print "input data file name without \'.dat\': " n=STDIN.readline n.chop! a="" open("#{n}.dat","rb"){|f| a=f.read} n=n.split(/\./)[0] a=a.split(/\[Data\]/) header=a[0].split("\x0d\x0a") data=a[1].split("\x0d\x0a") # header fw=0 wt=0 wrapw=0 ohpw=0 for l in header if l=~/INFO, NAME,\s+([\w\.]+)/ print "sample: #{$1}\n" fw=fmlwt($1) print "formula weight: #{fw}\n" end if l=~/INFO, WEIGHT, ([\d\.]+)/ print "sample weight: #{$1} mg\n" wt=$1.to_f/1000 end if l=~/INFO, COMMENT,\s+.*with\s+w?[rl]ap\s+([\d\.]+)mg/ print "with wrap #{$1} mg\n" wrapw=$1.to_f/1000 end if l=~/INFO, COMMENT,\s+.*with\s+ohp\s+([\d\.]+)mg/ print "with ohp #{$1} mg\n" ohpw=$1.to_f/1000 end end # data data.delete_if{|l| l=~/^$/} data=data.collect{|l| l.split(/,/)} ttl={} for i in 0...data[0].size ttl[data[0][i]]=i end d1=ttl["Temperature (K)"] d2=ttl["Long Moment (emu)"] d3=ttl["Field (Oe)"] d4=ttl["Long Scan Std Dev"] f=open("#{n}.txt","w") f.print <<-"HEAD" IGOR X NewDataFolder MT#{n} X SetDataFolder MT#{n} WAVES/D temp chi BEGIN HEAD for i in 1...data.size temp=data[i][d1].to_f moment=data[i][d2].to_f field=data[i][d3].to_f stdev=data[i][d4].to_f next if stdev/moment>0.01 field=1 if field.abs<1 chi=(moment/field-wrap(temp)*wrapw-ohp(temp)*ohpw)/wt*fw f.print "#{temp}\t#{chi}\n" end f.print <<-'TAIL' END X SetScale y 0,0," K", temp X SetScale y 0,0," emu", chi X Display chi vs temp X ModifyGraph grid=1,mirror=1,standoff=0,tick=2 X Label bottom "\\f02T\\f00 (\\U)" X Label left "\\[0\\F'Symbol'c\\F]0 (\\U mol\\S-1\\M)" X SetAxis/A/N=1/E=1 left X SetAxis/A/N=1 bottom X ModifyGraph mode=4,marker=19 X SetDataFolder :: TAIL f.close