\cancel mode verify

!**************************************************************
! Description:
!
! Usage: go taylor_frame [max=3] [ticks=0.2] [format="(f4.1)"] [xy_label="Standard Deviation"] [quadrants=1]
!
! arg 1: maximum axis length (in user units) 
! arg 2: delta (length) between major ticks
! arg 3: ppl format for x and y axes
! arg 4: Label on X and Y (r-axis) 
!        (e.g.,  "Standard Deviation (Normalized)"
!           or   "Standard Deviation (^oC)"
! arg 5: quadrants (1 = normal diagram (R positive); 2 = full diagram (R negative & positive)
!
! Example: 
!           yes? go taylor_frame.jnl 
!           yes? go taylor_frame.jnl 3 .2 " " "Standard Deviation (units)"
! 
!           yes? go taylor_frame.jnl 3 .2 " " "Standard Deviation (units)"
!           yes? go taylor_agraticule.jnl 3 " " 10 90 10
!           yes? go taylor_agraticule.jnl 3 " " 91 99 1
!           yes? go taylor_rgraticule.jnl 0.4 /DASH=(0.2,0.1,0.2,0.1)/COLOR=RED/THICK=2) 2.8 0.4
!           yes? go taylor_rgraticule.jnl 0.2 /DASH=(0.2,0.1,0.2,0.1)/COLOR=BLACK/THICK=1 2.6 0.4
!
! Notes:
!
! Calls: go ratio_set
!
! Author: Patrick Brockmann
! Contact: Patrick.Brockmann@ipsl.jussieu.fr
! $Date: 2012-06-06 10:44:30 -0700 (Wed, 06 Jun 2012) $
! $Name: $
! $Revision: 14116 $
! History:
! Modification:
! Original implentation: James.Orr@cea.fr 
!
! Modified: James Orr, 6 May 2009 (to allow for 2 quadrants, i.e., negative R's)
!******************************************************************~************

go ratio_set 1

let ME_rmax=$1%3%
let ME_tick=$2%.2%
def sym ME_axfmt=$3%(f4.1)%
def sym ME_labaxis=$4%Standard Deviation%
def sym quadrants $5%1%      !can be 1 (normal case) or 2 (when R's are negative & positive)

if ($quadrants%|1>TRUE|*>FALSE%) then
  let ME_haxbeg = 0
else
  let ME_haxbeg = `ME_rmax*(-1.)`
endif

! Draw 1 circle for axis extreme (maximum radius) 
! -----------------------------------------------
let ME_pi = atan(1.)*4.
let ME_deg2rad = 2*ME_pi/180
let ME_angle = (i-1)
let ME_xx = ME_rmax*cos(ME_pi*ME_angle/(100*2))
let ME_yy = ME_rmax*sin(ME_pi*ME_angle/(100*2))

if ($quadrants%|1>TRUE|*>FALSE%) then
  plot/set_up/nolab/i=1:101/line=1/hlimits=0:`ME_rmax`:`ME_tick`/vlimits=0:`ME_rmax`:`ME_tick`/vs ME_xx,ME_yy
else
  plot/set_up/nolab/i=1:201/line=1/hlimits=`ME_haxbeg`:`ME_rmax`:`ME_tick`/vlimits=0:`2*ME_rmax`:`ME_tick`/vs ME_xx,ME_yy
endif

ppl xfor "($ME_axfmt)"
ppl yfor "($ME_axfmt)"
ppl xlab "($ME_labaxis)"

if ($quadrants%|1>TRUE|*>FALSE%) then
  ppl ylab "($ME_labaxis)"
  ppl axset  0,1,1,0
else
  ppl axset  0,1,0,0
endif

ppl plot

! Plot simple vertical line (R=0)
plot/over/nolab/line/thick=1/col=black/vs  {0,0}, {0, `ME_rmax`}

! Label  curved "Correlation axis"
! -----------------------------------------------
if ($quadrants%|1>TRUE|*>FALSE%) then
! Place label on right at 45 degrees (center of theta axis for quadrant 1)
  let ME_xx = 1.08 * ME_rmax * cos(ME_pi/4)
  let ME_yy = 1.08 * ME_rmax * sin(ME_pi/4) 
  label `ME_xx` `ME_yy`  0 -45 .12 "Correlation"
else
! Place label at top center (just between 2 quadrants)
  let ME_xx = 1.13 * ME_rmax * cos(ME_pi/2)
  let ME_yy = 1.13 * ME_rmax * sin(ME_pi/2) 
  label `ME_xx` `ME_yy`  0   0 .12 "Correlation"
endif

! Make ticks on curved "Correlation axis"
! ----------------------------------------------
let ME_angle  =  j/100
let ME_xx = ME_rmax*cos(acos(ME_angle))
let ME_yy = ME_rmax*sin(acos(ME_angle))
repeat/j=10:90:10 plot/nolab/over/line=1/vs {`0.95*ME_xx`,`ME_xx`},{`0.95*ME_yy`,`ME_yy`}
repeat/j=5:95:10 plot/nolab/over/line=1/vs {`0.97*ME_xx`,`ME_xx`},{`0.97*ME_yy`,`ME_yy`}
repeat/j=91:99:1 plot/nolab/over/line=1/vs {`0.99*ME_xx`,`ME_xx`},{`0.99*ME_yy`,`ME_yy`}
if ($quadrants%|2>TRUE|*>FALSE%) then
  let ME_xx = ME_rmax*cos(acos(ME_angle*(-1)))
  repeat/j=10:90:10 plot/nolab/over/line=1/vs {`0.95*ME_xx`,`ME_xx`},{`0.95*ME_yy`,`ME_yy`}
  repeat/j=5:95:10 plot/nolab/over/line=1/vs {`0.97*ME_xx`,`ME_xx`},{`0.97*ME_yy`,`ME_yy`}
  repeat/j=91:99:1 plot/nolab/over/line=1/vs {`0.99*ME_xx`,`ME_xx`},{`0.99*ME_yy`,`ME_yy`}
endif

! Label ticks on curved "Standard Deviation axis"
! -----------------------------------------------
let ME_xx = 1.01 * ME_rmax * cos(acos(ME_angle))
let ME_yy = 1.01 * ME_rmax * sin(acos(ME_angle))
let ME_angletext = 2*acos(ME_angle)/ME_deg2rad
repeat/j=10:90:10 label `ME_xx` `ME_yy`  -1 `ME_angletext` .09 "`ME_angle`"
repeat/j=95:95:1  label `ME_xx` `ME_yy`  -1 `ME_angletext` .09 "`ME_angle`"
repeat/j=99:99:1  label `ME_xx` `ME_yy`  -1 `ME_angletext` .09 "`ME_angle`"
! Do the equivalent operations for the 2nd quadrant (negative R values)
if ($quadrants%|2>TRUE|*>FALSE%) then
  let ME_xx = 1.01 * ME_rmax * cos(acos(ME_angle*(-1)))
  let ME_angletext = 2*acos(ME_angle*(-1))/ME_deg2rad - 180
  repeat/j=10:90:10 label `ME_xx` `ME_yy`  +1 `ME_angletext` .09 "`ME_angle*(-1)`"
  repeat/j=95:95:1  label `ME_xx` `ME_yy`  +1 `ME_angletext` .09 "`ME_angle*(-1)`"
  repeat/j=99:99:1  label `ME_xx` `ME_yy`  +1 `ME_angletext` .09 "`ME_angle*(-1)`"
endif

!**************************************************************
cancel variable ME_*
cancel symbol ME_*

!**************************************************************
set mode verify

