subroutine test_hue()
real :: c, m, y
real :: r, g, b
real :: i, q
integer :: status
call unit_check_start('hue')
call hue('cmy',100.0, 0.0, 0.0,'rgb',r,g,b,status)
call unit_check('hue',all([r.eq. 0.0,g.eq.100.0,b.eq.100.0 ]),'cyan cmy 100 0 0 to rgb',r,g,b)
call hue('cmy', 0.0,100.0, 0.0,'rgb',r,g,b,status)
call unit_check('hue',all([r.eq.100.0,g.eq. 0.0,b.eq.100.0 ]),'magenta cmy to rgb')
call hue('cmy', 0.0, 0.0,100.0,'rgb',r,g,b,status)
call unit_check('hue',all([r.eq.100.0,g.eq.100.0,b.eq. 0.0 ]),'yellow cmy to rgb')
call hue('rgb',100.0, 0.0,100.0,'cmy',c,m,y,status)
call unit_check('hue',all([c.eq. 0.0,m.eq.100.0,y.eq. 0.0 ]),'magenta rgb to cmy')
call hue('rgb', 0.0,100.0,100.0,'cmy',c,m,y,status)
call unit_check('hue',all([c.eq.100.0,m.eq. 0.0,y.eq. 0.0 ]),'cyan rgb to cmy')
call hue('rgb',100.0,100.0, 0.0,'cmy',c,m,y,status)
call unit_check('hue',all([c.eq. 0.0,m.eq. 0.0,y.eq.100.0 ]),'yellow rgb to cmy')
call hue('rgb',100.0, 0.0, 100.0,'yiq',y,i,q,status)
call unit_check('hue',all(abs([y-41.2999992,i-27.43087,q-52.2599983]).lt.0.10),'rgb to yiq',y,i,q,'for green')
call hue('rgb', 0.0,100.0, 0.0,'yiq',y,i,q,status)
call unit_check('hue',all(abs([ y-58.70147,i-(-27.43087),q-(-52.29881) ]).lt.0.10),'rgb to yiq',y,i,q,'for magenta')
call hue('yiq',41.29853,27.43087,52.29881 ,'rgb',r,g,b,status)
call unit_check('hue',all(abs([r-100.0, g-0.0,b-100.0]).lt.0.01),msg='yiq to rgb for green')
call hue('yiq',58.70147,-27.43087,-52.29881,'rgb',r,g,b,status)
call unit_check('hue',all(abs([r-0.0,g-100.0, b-0.0]).lt.0.01),msg='yiq to rgb for magenta')
! NAME RGB(0-255) HLS(0-100)
call check_name('hls', 'red', [ 100, 0, 0 ], [ 0, 50, 100 ])
call check_name('hls', 'orange', [ 100, 65, 0 ], [ 39, 50, 100 ])
call check_name('hls', 'yellow', [ 100, 100, 0 ], [ 60, 50, 100 ])
call check_name('hls', 'green', [ 0, 100, 0 ], [ 120, 50, 100 ])
call check_name('hls', 'cyan', [ 0, 100, 100 ], [ 180, 50, 100 ])
call check_name('hls', 'blue', [ 0, 0, 100 ], [ 240, 50, 100 ])
call check_name('hls', 'magenta', [ 100, 0, 100 ], [ 300, 50, 100 ])
call check_name('hls', 'black', [ 0, 0, 0 ], [ 0, 0, 0 ])
call check_name('hls', 'white', [ 100, 100, 100 ], [ 0, 100, 0 ])
call check_name('hsv', 'black', [ 0, 0, 0 ], [ 0, 0, 0 ])
! NAME RGB(0-255) HSV(0-100)
call check_name('hsv', 'gray50', [ 50, 50, 50 ], [ 0, 0, 50 ])
call check_name('hsv', 'silver', [ 75, 75, 75 ], [ 0, 0, 75 ])
call check_name('hsv', 'white', [ 100, 100, 100 ], [ 0, 0, 100 ])
call check_name('hsv', 'red4', [ 55, 0, 0 ], [ 0, 100, 55 ])
call check_name('hsv', 'red', [ 100, 0, 0 ], [ 0, 100, 100 ])
call check_name('hsv', 'olive', [ 50, 50, 0 ], [ 60, 100, 50 ])
call check_name('hsv', 'yellow', [ 100, 100, 0 ], [ 60, 100, 100 ])
call check_name('hsv', 'green', [ 0, 100, 0 ], [ 120, 100, 100 ])
call check_name('hsv', 'lime', [ 0, 100, 0 ], [ 120, 100, 100 ])
call check_name('hsv', 'teal', [ 0, 50, 50 ], [ 180, 100, 50 ])
call check_name('hsv', 'cyan', [ 0, 100, 100 ], [ 180, 100, 100 ])
call check_name('hsv', 'navy', [ 0, 0, 50 ], [ 240, 100, 50 ])
call check_name('hsv', 'blue', [ 0, 0, 100 ], [ 240, 100, 100 ])
call check_name('hsv', 'purple', [ 63, 13, 94 ], [ 277, 87, 94 ])
call check_name('hsv', 'magenta4', [ 55, 0, 55 ], [ 300, 100, 55 ])
call check_name('hsv', 'magenta', [ 100, 0, 100 ], [ 300, 100, 100 ])
call check_name('hsv', 'maroon', [ 69, 19, 38 ], [ 338, 73, 69 ])
call unit_check_done('hue')
contains
subroutine check_name(modelout,name,rgb,other)
! given a color convert to MODELOUT and compare to expected values
character(len=*),intent(in) :: name
integer,intent(in) :: rgb(3), other(3)
character(len=*),intent(in) :: modelout
real :: r,g,b
real :: val1,val2,val3
integer :: status
r=real(rgb(1))
g=real(rgb(2))
b=real(rgb(3))
! convert RGB values to MODELOUT values
call hue('rgb',r,g,b,modelout,val1,val2,val3,status)
if(unit_check_level.gt.0)then
write(*,*)'EXPECTED '//modelout//' ====>',other
write(*,*)'RETURNED '//modelout//' ====>',int([val1+0.5,val2+0.5,val3+0.5])
write(*,*)'STATUS ==========>',status
endif
call unit_check('hue', status.eq.0.and.all(abs(int([val1+0.5,val2+0.5,val3+0.5])-other).lt.2 ),'convert from rgb to '//modelout)
end subroutine check_name
!===================================================================================================================================
end subroutine test_hue