c $Header: /usr/people/flittner/radtran/tomrad/pv2.2/src/RCS/slitavg.f,v 2.22 2000/08/30 16:38:09 flittner Exp $ real*8 function slitavg(x,y,nw,lam0,bw,itype) c spectrally average the data with a bandpass of bw implicit none c integer nw,itype real*8 x(nw),y(nw),bw,lam0 c integer i,is,ie real*8 y0,yn,w1,w2,wmin,wmax,sum,y1,dydx c c if itype = 0 then use rect filter c if itype = 1 then use triangle with fwhm=ibw c c find the first point c if(itype.eq.0)then wmin=lam0-bw*0.5d0 wmax=lam0+bw*0.5d0 else if(itype.eq.1)then wmin=lam0-bw wmax=lam0+bw endif c linear interpolation at the end points i=2 do while(wmin.gt.x(i)) i=i+1 if(i.gt.nw)then write(6,*)'center wavelength not in the data range' slitavg=0.0d0 return endif enddo dydx=(y(i)-y(i-1))/(x(i)-x(i-1)) y1=y(i-1)+dydx*(wmin-x(i-1)) is=i c find the last point i=nw-1 do while(wmax.lt.x(i)) i=i-1 if(i.eq.0)then write(6,*)'center wavelength not in the data range' slitavg=0.0d0 return endif enddo dydx=(y(i+1)-y(i))/(x(i+1)-x(i)) yn=y(i)+dydx*(wmin-x(i)) ie=i c weights for the points if(itype.eq.0)then w1=1.0d0/bw w2=w1 else if(itype.eq.1)then w1=0.0d0 w2=(1.0d0-abs(lam0-x(is))/bw)/bw endif c first panel sum=0.5d0*(x(is)-wmin)*(w1*y1+w2*y(is)) c now for the interior pts. w1=w2 do i=is+1,ie if(itype.eq.1)w2=(1.0d0-abs(lam0-x(i))/bw)/bw if((x(i-1).lt.lam0).and.(x(i).gt.lam0))then dydx=(y(i)-y(i-1))/(x(i)-x(i-1)) y0=y(i-1)+dydx*(lam0-x(i-1)) sum=sum+0.5d0*(lam0-x(i-1))*(w1*y(i-1)+y0/bw) sum=sum+0.5d0*(x(i)-lam0)*(w2*y(i)+y0/bw) else sum=sum+0.5d0*(x(i)-x(i-1))*(w1*y(i-1)+w2*y(i)) endif w1=w2 enddo c add in the last panel if(itype.eq.1)w2=0.0d0 sum=sum+0.5d0*(wmax-x(ie))*(w1*y(ie)+w2*yn) slitavg=sum return end