; this originally made 'size.eps' --> Fig. 3 from
; Tapia-Ignacio, Moctezuma, Donado, & Weeks, PRE 102, 022902 (2020).
;

filename='~/fig01'
set_plot,'ps'
device,file=filename+'.eps'
device,/color
loadct,76,file='~weeks/ericcol.tbl'

pfontold=!P.FONT
!P.FONT=1
device,set_font='Times',/tt_font

; --------------- START OF PLOTTING BELOW -----

rho=0.073;  mg/mm^2
; cols=reform(rgb2_24(bw2rgb3(indgen(256))))
cols=indgen(256)

cs=0.7
th=1.8
ss=0.8
x1=0.1 & x2 = 0.35
y1=0.05 & dy=0.20
y2=y1+dy+0.02
y3=y2+dy+0.02
b=" "
bb=[b,b,b,b,b,b,b]


cal = 60.0/4.0
; the data stored is slope of <r^2> vs frame.  The 60 converts
; from frames to seconds.  The 4 changes from <r^2> to D.
; Note that the MSD's are already in mm^2.


plot,sc(1,*),sc(2,*)*cal,/nodata, $
   ytitle=ktex2idl('$D_T$ (mm^2/s)'),/xlog,/ylog,yr=[0.1,30], $
   chars=cs,/ys,/xs,xr=[1,20],pos=[x1,y3,x2,y3+dy], $
   xtickn=bb
oplot,ncd(4,*),ncd(0,*)*cal,psym=circ(/fill),color=255,syms=ss
oplot,ncd(5,2:*),ncd(2,2:*)*cal,psym=symcat(17),color=160,syms=ss

xyouts,8,0.25*cal,ktex2idl('$\alpha$ = 1.72'),chars=cs,color=160
xyouts,2.3,0.02*cal,ktex2idl('$\alpha$ = 1.00'),chars=cs,color=255
xpos=14
ypos=15.0
xyouts,xpos,ypos,'(a)',chars=cs

x=alog(ncd(4,*)) & y=alog(ncd(0,*))
lf=linfit(x,y) & print,'DT actual slope circles = ',lf[1]
bc=mean(x+y)
xx1=[1.2,12]
oplot,xx1,exp(bc)/xx1*cal,color=0,thick=th
x=alog(ncd(5,2:*)) & y=alog(ncd(2,2:*))
lf=linfit(x,y) & print,'DT actual slope ellipse = ',lf[1]
be=mean(x+y)
xx2=[1.2,18]
oplot,xx2,exp(be)/xx2*cal,color=0,thick=th

rotcal = 0.5
; Fernando's data is 'slope' for rotational diffusion.  Using
; the idea that slope = 2D_R, the calibration factor is 1/2.
; My new data is also slope.
rotcal /= (180./3.14159)^2; to convert from degrees to radians
rotcal *= 60.0; to convert from frames to seconds



plot,sc(1,*),sc(3,*)*rotcal,/nodata, $
   ytitle=ktex2idl('$D_R$ (rad^2/s)'),/xlog,/ylog, $
 yr=[0.01,3.0],xtickn=bb, $
   chars=cs,/ys,/xs,xr=[1,20],pos=[x1,y2,x2,y2+dy],/noerase
oplot,ncd(4,*),ncd(1,*)*rotcal,psym=circ(/fill),color=255,syms=ss
oplot,ncd(5,2:*),ncd(3,2:*)*rotcal,psym=symcat(17),color=160,syms=ss

x=alog(ncd(4,*)) & y=alog(ncd(1,*)*rotcal)
lf=linfit(x,y) & print,'DR actual slope circles = ',lf[1]
rc=mean(2.0*x+y)
xx3=[1.2,12]
oplot,xx3,exp(rc)/xx3/xx3,color=0,thick=th
x=alog(ncd(5,2:*)) & y=alog(ncd(3,2:*)*rotcal)
lf=linfit(x,y) & print,'DR actual slope ellipse = ',lf[1]
re=mean(2.0*x+y)
xx4=[2.0,15]
oplot,xx4,exp(re)/xx4/xx4,color=0,thick=th

xyouts,xpos,ypos/10,'(b)',chars=cs

ratio1=ncd(0,*)*cal/(ncd(1,*)*rotcal)/ncd(4,*)
ratio2=ncd(2,2:*)*cal/(ncd(3,2:*)*rotcal)/ncd(5,2:*)
ratio1 = 1.0/ratio1/rho
ratio2 = 1.0/ratio2/rho

plot,ncd(4,*),ratio1,/nodata,xtitle=ktex2idl('$m$ (mg)'), $
   ytitle=ktex2idl('$m D_R$ / $\rho D_T$ (rad^2)'),/xlog,/ylog, $
   yr=[2,20.0],ytickn=['    '], $
   chars=cs,/ys,/xs,xr=[1,20],pos=[x1,y1,x2,y1+dy],/noerase
xv=0.95 & yv=0.95
xyouts,xv,2*yv,'2',chars=cs,align=1.0
xyouts,xv,5*yv,'5',chars=cs,align=1.0
xyouts,xv,10*yv,'10',chars=cs,align=1.0
xyouts,xv,20*yv,'20',chars=cs,align=1.0
oplot,ncd(4,*),ratio1,psym=circ(/fill),color=255,syms=ss
oplot,ncd(5,2:*),ratio2,psym=symcat(17),color=160,syms=ss
meanratio = mean([[ratio1],[ratio2]])
print,"CIRCLES:"
avgstd,ratio1
print,"ELLIPSES:"
avgstd,ratio2
print,"BOTH:"
avgstd,[[ratio1],[ratio2]]
hor,meanratio,color=0,thick=th

qx=1.05 & qy=1.0+(0.25*sqrt(2.0))
for i=2,n_elements(ncd(5,*))-1 do begin & $
  y=ratio2[i-2] & $
  x=ncd(5,i) & $
  oplot,[x/qx,x,x,x/qx],[y/qy,y/qy,y*qy,y*qy],color=0 & $
  oplot,[x*qx,x,x,x*qx],[y/qy,y/qy,y*qy,y*qy],color=0 & $
endfor


xyouts,xpos,15,'(c)',chars=cs

print,'DT scale factor circles = ',exp(bc)*cal
print,'DT scale factor ellipse = ',exp(be)*cal
print,'DR scale factor circles = ',exp(rc)
print,'DR scale factor ellipse = ',exp(re)

; ------------- END OF PLOTTING


!P.FONT=pfontold

device,/close
set_plot,'X'

spawn,'bbox_add.pl '+filename+'.eps'
spawn,'pagebbox.sh '+filename+'.eps'
spawn,'pstopnm -portrait -stdout -xsize=900 '+filename $
   +'.eps > ~/blah.ppm'
spawn,'pnmtojpeg -quality=95 ~/blah.ppm > '+filename+'.jpg'
spawn,'rm ~/blah.ppm'
cropjpg,filename+'.jpg'

; load in the JPEG and display it, just for fun:
read_jpeg,filename+'.jpg',tmp

; this is to shrink the image, if needed
tmp1=small(reform(tmp(0,*,*)))
nx=n_elements(tmp1(*,0))
ny=n_elements(tmp1(0,*))
tmp4=bytarr(3,nx,ny)
tmp4(0,*,*)=tmp1
tmp4(1,*,*)=small(reform(tmp(1,*,*)))
tmp4(2,*,*)=small(reform(tmp(2,*,*)))

erase
;tv,tmp,true=1    ; fullsize image
tv,tmp4,true=1   ; halfsize image

