!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!


      SUBROUTINE COMP_IR_EMISS (EMISS, wind,angle,nchn,np,mchannel) 1

#if defined (DOC)
!***********************************************************************
!
!**ID COMP_IR_EMISS -- INFRARED EMISSIVITY COMPUTATION
!
!       AUTHOR:   Thomas J. Kleespies               8 February 1998
!                 Physics Branch
!                 Satellite Research Laboratory
!                 Office of Research and Applications
!                 NOAA/NESDIS
!                 301-763-8136 x126
!                 301-763-8108 FAX
!                 Mailing Address: 810 NSC E/RA-14
!                                  NOAA/NESDIS
!                                  Washington, D.C. 20233
!                 Email: TKleespies@nesdis.noaa.gov
!
!                 L. GARAND     modified for NP points
!                 A. BEAULNE (CMDA/SMC)       April 2006  (ADAPT TO 3DVAR)
!
!       REVISION:
!
!       OBJECT:   COMPUTES WATER INFRARED EMISSIVITY FOR A SPECIFIC SET OF
!          CHANNEL INDICES, WIND SPEED AND ZENITH ANGLE.
!
!          Restrictions:  Must be compiled with /EXTEND_SOURCE or it's equivalent
!
!       ARGUMENTS:
!          INPUT:
!            -WIND(NP)         : SURFACE WIND SPEED (M/S)
!            -ANGLE(NP)        : VIEWING ANGLE (DEG)
!            -NCHN             : NUMBER OF CHANNELS TO PROCESS
!            -NP               : NUMBER OF LOCATIONS
!            -MCHANNELS(NCHN)  : VECTOR OF CHANNEL INDICES TO PROCESS
!
!          OUTPUT:
!            -EMISS(NCHN,NP)   : EMISSIVITIES (0.-1.)
!
!
!***********************************************************************
#endif

	Implicit None
	
	Integer MaxWn,NP
	Parameter (MaxWn = 19)	

	Integer Nparm
	Parameter (Nparm=3)
	Real Theta(Nparm,MaxWn)
	Real C(Nparm,2,MaxWn)
	Integer Nchn
     
        real WW
	Real Wind(NP),Angle(NP)
	Real Emiss(Nchn,NP)

	Integer Mchannel(Nchn)

	Integer MaxChan
	Parameter (MaxChan=19)
	Real A(MaxChan),B(MaxChan),CC(MaxChan)  ! local variables

	Common /IRemis/ A,B,CC


	Integer Index,Ichan,IP	
	
	Data Theta /                    &
     &   1700.381, 25.28534, 144.1023,  &
     &   1738.149, 25.67787, 146.6139,  &
     &   1769.553, 26.05250, 148.6586,  &
     &   1778.610, 26.12333, 149.5127,  &
     &   1794.245, 26.18523, 150.5874,  &
     &   1791.904, 26.19991, 150.7076,  &
     &   1806.872, 26.37132, 151.7191,  &
     &   1926.078, 27.63825, 160.7103,  &
     &   1969.155, 28.02767, 163.6069,  &
     &   1975.549, 27.86465, 164.6228,  &
     &   1991.288, 27.94312, 166.2924,  &
     &   2082.691, 28.93558, 172.4025,  &
     &   2182.872, 29.89974, 179.5839,  &
     &   2338.510, 31.27507, 191.2063,  &
     &   2164.615, 28.97152, 182.6279,  &
     &   2099.714, 29.91868, 178.4015,  &
     &   1857.644, 29.13640, 160.9822,  &
     &   1610.696, 26.48602, 142.2768,  &
     &   1503.969, 24.97931, 133.4392 /

        Data C /	                             &
     &  0.9715104043561414,-1.2034233230944147E-06,  &
     &  -5.8742655960993913E-07,  &
     &  0.9263932848727608,-9.4908630939690859E-04,  &
     &  2.2831134823358876E-05,   &
     &  0.9732503924722753,-1.2007007329295099E-06,  &
     &  -5.8767355551283423E-07,  &
     &  0.9290947860585505,-9.5233413988900161E-04,  &
     &  2.2640835623043761E-05,   &
     &  0.9745005204317289, 1.2857517639804244E-06,  &
     &  -7.1356127087301190E-07,  &
     &  0.9310852809117095,-9.5453509182819095E-04,  &
     &  2.2562638663187251E-05,   &
     &  0.9756204829761132, 1.2979181109743976E-06,  &
     &  -7.1406809362820139E-07,  &
     &  0.9329073568177888,-9.5627536945214183E-04,  &
     &  2.2442358508999558E-05,   &
     &  0.9764012672766408,-2.0826654381361387E-06,  &
     &  -4.9103920569405721E-07,  &
     &  0.9341937281933334,-9.5764423928102976E-04,  &
     &  2.2326701573603621E-05,   &
     &  0.9770513558720460, 4.1867599593267133E-07,  &
     &  -6.1768073971231931E-07,  &
     &  0.9352981872014672,-9.5833614545300181E-04,  &
     &  2.2261996883974513E-05,   &
     &  0.9775970810179080,-1.2289690625562906E-06,  &
     &  -5.2953762169985775E-07,  &
     &  0.9362188153954743,-9.5950872922696905E-04,  &
     &  2.2251301675423482E-05,   &
     &  0.9830610391451819, 2.7693589475690676E-07,  &
     &  -5.1580217018207558E-07,  &
     &  0.9461121192685766,-9.5718115604053031E-04,  &
     &   2.1087308573177295E-05,  &
     &  0.9840097930773377,-1.4987900189155091E-06,  &
     &  -3.8281408128977038E-07,  &
     &  0.9479758694804105,-9.5451252460440695E-04,  &
     &  2.0800627740862229E-05,   &
     &  0.9851056150728580,-6.5768237152417477E-07,  &
     &  -4.2053769829400935E-07,  &
     &  0.9502084544618980,-9.4965534997704157E-04,  &
     &   2.0326602209199427E-05,  &
     &  0.9862706396188835,-2.3713068057993353E-06,  &
     &  -2.8671134918457728E-07,  &
     &  0.9526580467595886,-9.4614505430749598E-04,  &
     &   2.0001856872595840E-05,  &
     &  0.9875307221489201, 1.3003462826947714E-07,  &
     &  -4.1335288320283954E-07,  &
     &  0.9554195617948236,-9.3806678196435643E-04,  &
     &   1.9407754748128057E-05,  &
     &  0.9891153260567763,-8.0730206675976713E-07,  &
     &  -3.1811320626834656E-07,  &
     &  0.9590558393678170,-9.2716287670223167E-04,  &
     &  1.8690586764925213E-05,   &
     &  0.9913304557147524,-2.1153391229093421E-08,  &
     &  -3.1094269595901165E-07,  &
     &  0.9644162604969492,-9.0342753739935612E-04,  &
     &  1.7274993357160937E-05,   &
     &  0.9925188366950193,-4.6365959315123653E-07,  &
     &  -2.7020120347068712E-07,  &
     &  0.9667877170960085,-9.0665804037922043E-04,  &
     &  1.7083616616646458E-05,   &
     &  0.9919408379810360,-2.0563508815953840E-06,  &
     &  -1.8066722718403761E-07,  &
     &  0.9627535343397309,-9.7537134133678965E-04,  &
     &   1.9698263973541952E-05,  &
     &  0.9889406296815972,-2.3713068057993353E-06,  &
     &  -2.8671134918457728E-07,  &
     &  0.9506051906192242,-1.0642902225813857E-03,  &
     &   2.4235485973033298E-05,  &
     &  0.9828819693848310,-7.4086701870172759E-07,  &
     &  -6.2949258820534062E-07,  &
     &  0.9329616683158125,-1.0728027288012200E-03,  &
     &  2.7209071863380586E-05,   &
     &  0.9767410313266288,-9.1750038410238915E-07,  &
     &  -7.9177921107781349E-07,  &
     &  0.9192775350344998,-1.0369254272157462E-03,  &
     &  2.8000594542037504E-05    &
     &   /


	Save Theta,C


	Do Ichan = 1 , Nchn

        Index = Mchannel(Ichan)

        DO IP=1,NP

        WW=WIND(IP)
	 A(Ichan) = C(1,1,Index) + C(2,1,Index)*WW    &  
     &		                 + C(3,1,Index)*WW*WW
	 B(Ichan) = C(1,2,Index) + C(2,2,Index)*WW    &
     &                           + C(3,2,Index)*WW*WW

	 CC(Ichan) = Theta(1,Index) + Theta(2,Index)*WW

	 Emiss(Ichan,IP) = A(Ichan) + (B(Ichan)-A(Ichan)) *   & 
     &            Exp(( (Theta(3,Index)-60.)**2.              &
     &        - (Angle(IP)-Theta(3,Index))**2. )/CC(Ichan))

        ENDDO

	EndDo

	Return
	End