! trackplot_demo.jnl
! *jd* 5.99
! *acm* 7/01 update /line=  to /color=/thickness=

! Description: demonstrate usage of trackplot jnl file

set mode verify


if ($program_name"0|PyFerret>1|*>0") THEN set text/font=arial


! Define a 3-leg plot track with discontinuities
LET/QUIET     X0 = 240
LET/QUIET     Y0 = 10
LET/QUIET     X1 = 180
LET/QUIET     Y1 = 60
LET/QUIET     X2 = 150
LET/QUIET     Y2 = 10
LET/QUIET     XLEG1 = X0 + (L-1)*(X1-X0)/50
LET/QUIET     YLEG1 = Y0 + (L-1)*(Y1-Y0)/50
LET/QUIET     XLEG2 = X1 + (L-51)*(X2-X1)/20
LET/QUIET     YLEG2 = Y1 + (L-51)*(Y2-Y1)/20
LET/QUIET     LCURVE = L-71
LET/QUIET     R0 = 35
LET/QUIET     RADIUS = R0 - LCURVE/3
LET/QUIET     XLEG3 = X2+R0 - RADIUS * COS(LCURVE/12)
LET/QUIET     YLEG3 = Y2 - RADIUS * SIN(LCURVE/12)
LET/QUIET     XSTRAIGHT = IF L LE 50 THEN XLEG1 ELSE XLEG2
LET/QUIET     YSTRAIGHT = IF L LE 50 THEN YLEG1 ELSE YLEG2
LET/QUIET     XTRACK = IF L LE 70 THEN XSTRAIGHT ELSE XLEG3
LET/QUIET     YTRACK = IF L LE 70 THEN YSTRAIGHT ELSE YLEG3

LET/QUIET     MY_VAR = SIN(L/2)
LET/QUIET     OTHER_VAR = RANDN(L) + 1 
SET REGION/L=1:120
 
! Plot variable "my_var" as a red line, "other_var" in blue
! over the ship track in black
! Use automatic scaling and baseline of plot
go basemap x=120:260 Y=25s:65n 20
plot/vs/line/over/title="Ship track" xtrack, ytrack
go trackplot plot/vs/over/line/color=red/title="Variable MY_VAR" xtrack ytrack my_var
go trackplot plot/vs/over/line/color=blue/title="Variable OTHER_VAR" xtrack ytrack other_var
label/nouser `($ppl$xlen)/2` -1 0 0 .18 "@CRSynthetic track and 2 variables"
frame/file=trackplot_demo_1.png
\PAUSE

! Try again, but scale the data smaller and shift baseline of other_var 
SAY ($TRACKPLOTscale)			! notice default scaling = 5.5983 units/inch
go basemap x=120:260 Y=25s:65n 20 
plot/vs/line/over/title="Ship track" xtrack, ytrack
go trackplot plot/vs/over/line/color=red/title="Variable MY_VAR" xtrack ytrack my_var 12
go trackplot plot/vs/over/line/color=blue/title="Variable OTHER_VAR" xtrack ytrack other_var 12 1
frame/file=trackplot_demo_2.png
\PAUSE

! In this demo we will mark every 10th point on the ship track
! and put scale markers onto the plot
go basemap x=120:260 Y=25s:65n 20
plot/vs/line/over/title="Ship track" xtrack, ytrack
plot/vs/over/NOLABEL/SYMBOL=88 xtrack[L=1:120:10], ytrack[L=1:120:10]
if ($program_name"0|PyFerret>1|*>0") THEN 
  label 220,-10,-1,0,.1 "Star every 10<sup>th</sup> point"
else
  label 220,-10,-1,0,.1 "@PM88@CR - every 10^t^h point"
endif
label 220,-10,-1,0,.1 "Star every 10<sup>th</sup> point"
go trackplot plot/vs/over/line/color=red/title="Variable MY_VAR" xtrack ytrack my_var 4
go scalemark 1 -1 2    ! position outside of plot rectangle using inches
go trackplot plot/vs/over/line/color=blue/title="Variable OTHER_VAR" xtrack ytrack other_var " " 1
go scalemark 180 0 2 user "2 units"
label/user 180 -3 0 0 .08 "random values plus 1"
frame/file=trackplot_demo_3.png
