#!/usr/local/bin/ruby # read from data file and output igortxt def fmlwt(fml) #weight and formula (weight) awt={} IO::foreach("formula.dat") do |l| if l=~/([A-Z][a-z]?)\s+([\d\.]*)/ awt[$1]=$2.to_f end end fw=0 while fml.size>0 break unless m=/([A-Z][a-z]?)(\d*)/.match(fml) aw=awt[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 def rot(t) w=[2.6322e-08,-4.9065e-12] return w[0]+w[1]*t end # main #print "input data file name without \'.dat\': " #n=STDIN.readline #n.chop! n=ARGV[0] a="" open("#{n}","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=1 wt=0 wrapw=0 ohpw=0 rotw=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\.]+)/ wt=$1.to_f wt=1000 if wt==0 print "sample weight: #{wt} mg\n" wt/=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 if l=~/INFO, COMMENT,\s+.*with\s+rotator/ print "with rotator\n" rotw=1 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(sprintf("MH#{n}.txt",n),"w") f.print <<-"HEAD" IGOR X NewDataFolder MH#{n} X SetDataFolder MH#{n} WAVES/D field mag BEGIN HEAD # muB=9.27e-21emu,NA=6.02e23 for i in 1...data.size next if data[i][d4].to_f/data[i][d2].to_f>0.02 temp=data[i][d1].to_f field=data[i][d3].to_f mag=(data[i][d2].to_f-(wrap(temp)*wrapw+ohp(temp)*ohpw+rot(temp)*rotw)*field)/wt*fw f.print "#{field}\t#{mag}\n" end f.print <<-'TAIL' END X SetScale y 0,0,"G", field X SetScale y 0,0," emu", mag X Duplicate mag dmdh X Duplicate field dh X Differentiate dmdh,dh X dmdh/=dh X Duplicate mag mub X mub/=5585 X SetScale y 0,0," ", mub X SetScale y 0,0," emu", dmdh X Smooth 2, dmdh X Display mag vs field X ModifyGraph grid=1,mirror=1,standoff=0,tick=2 X AppendToGraph/R dmdh vs field X ModifyGraph standoff=0,tick=2 X Label bottom "\\f02H\\f00 (\\U)" X Label left "\\f02M\\f00 (\\U mol\\S-1\\M)" X Label right "\\f02dM\\f00/\\f02dH\\f00 (\\U mol\\S-1\\M)" X SetAxis/A/N=1/E=1 left X SetAxis/A/N=1/E=1 right X SetAxis/A/N=1 bottom X ModifyGraph mode(dmdh)=0 X ModifyGraph mode(mag)=4,marker=19 X Display mub vs field X ModifyGraph grid=1,mirror=1,standoff=0,tick=2 X Label bottom "\\f02H\\f00 (\\U)" X Label left "\\f02M\\f00 (\\[0\\F'Symbol'm\\F]0\\BB\\M mol\\S-1\\M)" X SetAxis/A/N=1/E=1 left X SetAxis/A/N=1 bottom X SetDataFolder :: TAIL f.close