!-----------------------------------------------------------------------
! This procedure will display:
! - the named LUT,
! - the RGB and HSV values along the LUT,
! - the greyed LUT (useful to check what happens on black-and-white
!   printers),
! - the luminance along the LUT.
!-----------------------------------------------------------------------

if pro%narg.ne.1 then
  message e lut-analysis  "Missing LUT name as argument"
  return base
endif

! Dummy data
define real x[512,2]
define real y z /like x
let x[i,j] i
let y[i,j] j
let z[i,j] i
rgdata x y z /blank -1000
limits /rg

!
clear directory
change lut static
define real bxmin bxmax
let bxmin 3
let bxmax 27.0

! LUT
lut 'pro%arg[1]'
g\set box_loc bxmin bxmax 17 19
g\plot
g\box n n n
g\draw text 0 0.3 "LUT "'pro%arg[1]' /box 8

! RGB
g\set box_loc bxmin bxmax 13.5 16.5
g\limits 0 1 0 1 /margin 0 10
g\box n o
define real xl[65535]
let xl[i] i/65535
pen /col red
g\connect xl lut%red
g\draw text -1.4 0 "Red" 5 90 /box 4
pen /col lime_green
g\connect xl lut%green
g\draw text -2.0 0 "Green" 5 90 /box 4
pen /col blue
g\connect xl lut%blue
g\draw text -2.6 0 "Blue" 5 90 /box 4
pen /def

! HSV
g\set box_loc bxmin bxmax 10.0 13.0
g\limits 0 1 0 1 /margin 0 10
g\axis xl /label n
g\axis yl
g\axis xu
pen /col dark_turquoise
g\connect xl lut%saturation
g\draw text -1.4 0 "Saturation" 5 90 /box 4
pen /col orange
g\connect xl lut%value
g\draw text -2.0 0 "Value" 5 90 /box 4
pen /def
!
g\limits 0 1 0 360 /margin 0 10
g\axis yr /label o
pen /col purple
g\connect xl lut%hue
g\draw text 1.6 0 "Hue" 5 90 /box 6
pen /def

! Grey luminance. See comments in Fortran subroutine rgb_to_grey
define real g /like xl
let g 0.3*lut%red+0.59*lut%green+0.11*lut%blue  ! Natural
! let g 0.333*lut%red+0.333*lut%green+0.333*lut%blue  ! Direct
! let lut%saturation 0.  ! Desaturate
g\set box_loc bxmin bxmax 5.5 7.5
let lut%red g
let lut%green g
let lut%blue g
let lut%mode 2
lut lut
g\limits /rg
g\plot
g\box n n n
g\draw text 0 0.3 "Grey luminance (natural)" /box 8
!
g\set box_loc bxmin bxmax 2.0 5.0
g\limits 0 1 0 1 /margin 0 10
g\connect xl g
g\box n o
g\draw text -1.4 0 "Grey" 5 90 /box 4
