test_color_name2rgb Subroutine

public subroutine test_color_name2rgb()

Arguments

None

Contents

Source Code


Subroutines

subroutine check_name(name, rgb)

Arguments

Type IntentOptional Attributes Name
character(len=*) :: name
integer, intent(in) :: rgb(3)

Source Code

subroutine test_color_name2rgb()

call unit_check_start('color_name2rgb')
   !                NAME       RGB(0-255)
   call check_name('black',    [ 0,    0,    0   ])
   call check_name('blue',     [ 0,    0,    100 ])
   call check_name('cyan',     [ 0,    100,  100 ])
   call check_name('gray50',   [ 50,   50,   50  ])
   call check_name('green',    [ 0,    100,  0   ])
   call check_name('magenta',  [ 100,  0,    100 ])
   call check_name('magenta4', [ 55,   0,    55  ])
   call check_name('maroon',   [ 69,   19,   38  ])
   call check_name('navy',     [ 0,    0,    50  ])
   call check_name('olive',    [ 50,   50,   0   ])
   call check_name('orange',   [ 100,  65,   0   ])
   call check_name('purple',   [ 63,   13,   94  ])
   call check_name('red',      [ 100,  0,    0   ])
   call check_name('red4',     [ 55,   0,    0   ])
   call check_name('silver',   [ 75,   75,   75  ])
   call check_name('teal',     [ 0,    50,   50  ])
   call check_name('white',    [ 100,  100,  100 ])
   call check_name('yellow',   [ 100,  100,  0   ])
   call check_name('lime',     [ 0,    100,  0   ])

call unit_check_done('color_name2rgb')
contains
subroutine check_name(name,rgb)
! given a colorname look up RGB values, compare to expected values, check

character(len=*)   :: name
integer,intent(in) :: rgb(3)
real               :: r,g,b
real               :: r1,g1,b1
real               :: r2,g2,b2
character(len=20)  :: echoname
character(len=20)  :: closestname
   call color_name2rgb(name,r,g,b,echoname)                                   ! given a color name look up RGB values in range 0-100
   call unit_check('color_name2rgb',echoname.ne.'Unknown',msg='make sure echoed name does not equal unknown')
   call unit_check('color_name2rgb',all(int([r+0.5,g+0.5,b+0.5]).eq.rgb),msg='check returned RGB values against expected values' )

   call closest_color_name(r,g,b,closestname)                                 ! see if get name back
   if(closestname.eq.name)then
      call unit_check('color_name2rgb',closestname.eq.name,msg='names match for '//name)
   else                                                     ! did not get back name put in; but maybe alternate alias
      ! if values the same assume OK
      call color_name2rgb(closestname,r1,g1,b1,echoname)
      call color_name2rgb(name,r2,g2,b2,echoname)
      call unit_check('color_name2rgb',     &
      & int(r1+0.5) .eq. int(r2+0.5) .and. &
      & int(g1+0.5) .eq. int(g2+0.5) .and. &
      & int(b1+0.5) .eq. int(b2+0.5)  ,msg='close enough for NAME: '//trim(name)//' CLOSESTNAME: '//trim(closestname) )
   endif

end subroutine check_name
!===================================================================================================================================
end subroutine test_color_name2rgb