!-----------------------------------------------------------------------
! Plot all the possible pen colours.
! Default is to do the plot in a dedicated window without modifying
! the current user plots. If argument "<GREG" is present, plot in main
! <GREG window instead.
!-----------------------------------------------------------------------

begin procedure plot-lut-globals
  if exist(demo%lut)  del /var demo%lut
  if .not.exist(demo)  define structure demo /global
  define structure demo%lut /global
  define logical demo%lut%useother /global
  define integer demo%lut%nrows /global
  define integer demo%lut%icol /global
  define real demo%lut%xinc demo%lut%yinc /global
  define real demo%lut%xw demo%lut%yw /global
  ! Buffer for one list
  define character*32 demo%lut%name /global
  define character*16 demo%lut%file[20] /global
  define integer demo%lut%nfile /global
end procedure plot-lut-globals

begin procedure plot-lut-list
  define integer ilut fcol lcol
  let fcol demo%lut%icol+1
  let ilut 1
  for /while yes
    let demo%lut%icol demo%lut%icol+1
    for jcol demo%lut%nrows to 1 by -1
      g\set box_loc demo%lut%xinc*demo%lut%icol-demo%lut%xw -
                    demo%lut%xinc*demo%lut%icol+demo%lut%xw -
                    demo%lut%yinc*jcol-demo%lut%yw -
                    demo%lut%yinc*jcol+demo%lut%yw
      @ plot-lut-one 'demo%lut%file[ilut]'
      !
      let ilut ilut+1
      if (ilut.gt.demo%lut%nfile)  break
    next jcol
    if (ilut.gt.demo%lut%nfile)  break
  next
  let lcol demo%lut%icol
  !
  g\set box_loc (fcol-0.5)*demo%lut%xinc -
                (lcol+0.5)*demo%lut%xinc -
                0.55*demo%lut%yinc -
                (demo%lut%nrows+0.6)*demo%lut%yinc
  g\box n n n
  g\draw text 0. 0.5 'demo%lut%name' 5 /box 8
end procedure plot-lut-list

begin procedure plot-lut-one
  !
  lut 'pro%arg[1]'
  plot
  pen /col grey
  box n n n
  pen /col foreground
  g\draw text 0 0.3 'pro%arg[1]' 5 /box 8
  !
end procedure plot-lut-one

@ plot-lut-globals

if (pro%narg.ge.1) then
  let demo%lut%useother pro%arg[1].ne."<GREG"
else
  let demo%lut%useother yes
endif

if (demo%lut%useother) then
  ! Perform the plot in a dedicated window
  define char*32 oldpwd
  let oldpwd 'gtv%pwd'
  g\gtv search <luts
  if (.not.gtv%exist)  g\create directory <luts
  g\change directory <luts
endif

clear directory
g\set /def
!
! Dummy data
define real x[128,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

let demo%lut%nrows 10
let demo%lut%xinc page_x/10.0
let demo%lut%yinc page_y/11.3
let demo%lut%xw demo%lut%xinc*0.4
let demo%lut%yw demo%lut%yinc*0.2

g\change lut static
g\set char 0.5

! --- Various categories ---

let demo%lut%name  "Linear"
let demo%lut%nfile 20
let demo%lut%file[1:20] -
  "cet-l01.lut" "cet-l02.lut" "cet-l03.lut" "cet-l04.lut" "cet-l05.lut" -
  "cet-l06.lut" "cet-l07.lut" "cet-l08.lut" "cet-l09.lut" "cet-l10.lut" -
  "cet-l11.lut" "cet-l12.lut" "cet-l13.lut" "cet-l14.lut" "cet-l15.lut" -
  "cet-l16.lut" "cet-l17.lut" "cet-l18.lut" "cet-l19.lut" "cet-l20.lut"
@ plot-lut-list

let demo%lut%name  "Diverging"
let demo%lut%nfile 13
let demo%lut%file[1:13] -
  "cet-d01a.lut" "cet-d01.lut" "cet-d02.lut" "cet-d03.lut" "cet-d04.lut" -
  "cet-d06.lut"  "cet-d07.lut" "cet-d08.lut" "cet-d09.lut" "cet-d10.lut" -
  "cet-d11.lut"  "cet-d12.lut" "cet-d13.lut"
@ plot-lut-list

let demo%lut%name  "Rainbow"
let demo%lut%nfile 4
let demo%lut%file[1:4] -
  "cet-r1.lut" "cet-r2.lut" "cet-r3.lut" "cet-r4.lut"
@ plot-lut-list

let demo%lut%name  "Cyclic"
let demo%lut%nfile 14
let demo%lut%file[1:14] -
  "cet-c1.lut"  "cet-c1s.lut" "cet-c2.lut"  "cet-c2s.lut" "cet-c3.lut"  -
  "cet-c3s.lut" "cet-c4.lut"  "cet-c4s.lut" "cet-c5.lut"  "cet-c5s.lut" -
  "cet-c6.lut"  "cet-c6s.lut" "cet-c7.lut"  "cet-c7s.lut"
@ plot-lut-list

let demo%lut%name  "Isoluminant"
let demo%lut%nfile 3
let demo%lut%file[1:3] -
  "cet-i1.lut" "cet-i2.lut" "cet-i3.lut"
@ plot-lut-list

let demo%lut%name  "Color blind"
let demo%lut%nfile 5
let demo%lut%file[1:5] -
  "cet-cbc1.lut" "cet-cbc2.lut" "cet-cbd1.lut" "cet-cbl1.lut" "cet-cbl2.lut"
@ plot-lut-list

! --- Cleaning ---
if demo%lut%useother  g\change directory 'oldpwd'
