C
C	$Id: yiqrgb.f,v 1.3 2000/08/22 15:02:30 haley Exp $
C                                                                      
C                Copyright (C)  2000
C        University Corporation for Atmospheric Research
C                All Rights Reserved
C
C This file is free software; you can redistribute it and/or modify
C it under the terms of the GNU General Public License as published
C by the Free Software Foundation; either version 2 of the License, or
C (at your option) any later version.
C
C This software is distributed in the hope that it will be useful, but
C WITHOUT ANY WARRANTY; without even the implied warranty of
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
C General Public License for more details.
C
C You should have received a copy of the GNU General Public License
C along with this software; if not, write to the Free Software
C Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
C USA.
C
      SUBROUTINE YIQRGB ( Y, I, Q, R, G, B )
C
C_BEGIN PROLOGUE YIQRGB
C
C_PURPOSE
C    This subroutine converts a color specification given in
C    the YIQ coordinate system to the equivalent color
C    specification in the Red, Green, Blue coordinate system.
C
C_DESCRIPTION
C    This subroutine converts color values given in the
C    YIQ coordinate system to colors in the RGB coordinate
C    system.  The input value Y is in the range [0.,1.];
C    I is in the range [-.6,.6]; Q is in the range [-.52,.52].
C    The output values R, G, and B are red, green, and blue
C    intensities in the range [0.,1.] .
C
C_ARGUMENTS
C
C Y       (INPUT,SINGLE,VARIABLE)  A real variable in the range
C         [0.,1.] .  Y is the color component of a television
C         signal which is shown on black-and-white televisions;
C         Y minimizes the effect of two colors appearing different
C         to the human eye but mapping to similar monochrome
C         intensities.
C
C I       (INPUT,SINGLE,VARIABLE)  A real variable in the range
C         [-.6,.6] .
C
C Q       (INPUT,SINGLE,VARIABLE)  A real variable in the range
C         [-.52,.52].
C
C R       (OUTPUT,SINGLE,VARIABLE)  A real variable in the range
C         [0.,1.] which represents the red intensity component
C         of the output color in RGB color space.
C
C G       (OUTPUT,SINGLE,VARIABLE)  A real variable in the range
C         [0.,1.] which represents the green intensity component
C         of the output color in RGB color space.
C
C B       (OUTPUT,SINGLE,VARIABLE)  A real variable in the range
C         [0.,1.] which represents the blue intensity component
C         of the output color in RGB color space.
C
C_I/O
C    (NONE)
C
C_ROUTINES CALLED
C    (NONE)
C
C_COMMON BLOCKS
C    (NONE)
C
C_MAXIMUM GKS LEVEL
C    (NONE)
C
C_LANGUAGE
C    FORTRAN
C
C_REVISION DATE
C    880511 (YYMMDD)
C
C_HISTORY
C    This subroutine was originally coded and prepared for the
C    NCAR Graphics package by Fred Clare based on algorithms
C    in Foley and van Dam (see REFERENCES below).
C
C_REFERENCES
C    Foley, James D. and van Dam, Andries,"Fundamentals of Interactive
C    Computer Graphics",Addison-Wesley Publishing Company, 1982.
C
C_EXAMPLES
C    Example 1 --  Convert green from YIQ to RGB.
C          SUBROUTINE TYIQ2
C          REAL    R,G,B,EPS
C          PARAMETER (EPS=0.01)
C          CALL YIQRGB(.59,-.28,-.52,R,G,B)
C          IF ( (ABS(R-0.) .GT. EPS) .OR. (ABS(G-1.) .GT. EPS) .OR.
C         *     (ABS(B-0.) .GT. EPS) ) THEN
C            IUN = I1MACH(4)
C            WRITE(IUN,10)
C          ENDIF
C          RETURN
C       10 FORMAT(' TYIQ2 returned incorrect values')
C          END
C
C_END PROLOGUE YIQRGB
C
      REAL   R,G,B,Y,I,Q
C
C  Check on the input values.
C
C_FIRST EXECUTABLE STATEMENT YIQRGB
C
      R = Y +  .95*I +  .62*Q
      G = Y -  .28*I -  .64*Q
      B = Y - 1.11*I + 1.73*Q
      RETURN
      END
