;$Id: ppol.pro,v 1.5 2020/08/12 18:40:41 roper Exp $
;
;  before running this, run first ppolmag.pro
;
restore,'specm.sav'
;plot_oo,k[1:*],grav1m[1:*]
;oplot,k[1:*],grav2m[1:*]
;oplot,k[1:*],-grav2m[1:*]
;oplot,k[1:*],-grav2m[1:*],col=122
;oplot,k[1:*],grav2m[1:*]/grav1m[1:*]
;plot,k[1:*],grav2m[1:*]/grav1m[1:*]
;plot_oi,k[1:*],grav2m[1:*]/grav1m[1:*]
plot,k[1:*],grav2m[1:*]/grav1m[1:*]
;
dk=k[1]-k[0]
grav1mm=dk*total(grav1m)
grav2mm=dk*total(grav2m)
;
pol1=grav2mm/grav1mm
pol2=mean(grav2m[1:*]/grav1m[1:*])
;
pc_read_param,/param2,o=param
sig=param.relhel
;
;  read magnetic polarization
;
default,t0,1.1
file='polmag.txt'
a=rtable(file,3)
t=reform(a[0,*])
hel1t=reform(a[1,*])
hel2t=reform(a[2,*])
good=where(abs(t-t0) lt .0001)
hel1=(hel1t(good))[0]
hel2=(hel2t(good))[0]
;
;  print
;
cwd,run
fo='(f6.3,e10.2,2f9.5,1x,2f9.5,2x,a)'
openw,1,'tmp.txt'
printf,1,sig,grav1mm,pol1,pol2,hel1,hel2,run,fo=fo
close,1
spawn,'cat tmp.txt'
spawn,'cat tmp.txt >> ../idl/pol.txt'
END
