!+ Subroutine to read a filter function.
!
! Method:
!	Straightforward.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date			Comment
!	1.0		12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77  with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      SUBROUTINE READ_FILTER(IERR
     &   , N_FILTER, WAVENUMBER_FILTER, TRANS_FILTER)
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/dimensions_obs.ucf'
      INCLUDE 'incl/def_data_in.icf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
     &   , N_FILTER
!             NUMBER OF FILTER POINTS
      REAL*8
     &     WAVENUMBER_FILTER(NPD_FILTER)
!             WAVENUMBERS OF FILTER POINTS
     &   , TRANS_FILTER(NPD_FILTER)
!             TRANSMISSION AT FILTER POINTS
!
!     LOCAL VARIABLES
      CHARACTER
     &     LINE*80
!             INPUT STRING
     &   , FILE_FILTER*80
!             NAME OF FILTER FILE.
      INTEGER
     &     IOS
!             I/O ERROR FLAG
     &   , I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
      LOGICAL
     &     L_MICRON
!             TRUE IF UNITS ARE MICRONS
     &   , L_METRE
!             TRUE IF UNITS ARE METRES
     &   , L_NANOMETRE
!             TRUE IF UNITS ARE NANOMETRES
     &   , L_INVERSE_CM
!             TRUE IF UNITS ARE INVERSE CMS.
!
!
      WRITE(IU_USER, '(/A)')
     &   'ENTER THE NAME OF THE FILTER FILE.'
      READ(IU_STDIN, '(A)') FILE_FILTER
      OPEN(UNIT=IU_FILTER, FILE=FILE_FILTER, IOSTAT=IOS, STATUS='OLD')
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(/A)') '*** ERROR OPENING FILTER FILE.'
         IERR=I_ERR_FATAL
         RETURN
      ENDIF
!
!     READ LINE UNTIL FILTER DIRECTIVE IS FOUND.
1     READ(IU_FILTER, '(A)') LINE
      IF (LINE(1:7).NE.'*FILTER') GOTO 1
!
!     READ HEADER TO FIND UNIT.
      READ(IU_FILTER, '(A)') LINE
      J=0
2        J=J+1
         IF (J.LE.78) THEN
            IF (LINE(J:J).NE.'(') GOTO 2
         ELSE
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: LINE FOLLOWING *FILTER DIRECTIVE '
     &         //'IS INCORRECT.'
         ENDIF
!
!     INITIALIZE THE UNIT FLAGS TO .FALSE.
      L_METRE=.FALSE.
      L_MICRON=.FALSE.
      L_NANOMETRE=.FALSE.
      L_INVERSE_CM=.FALSE.
!
      IF (LINE(J+1:J+1).EQ.'M') THEN
         L_METRE=.TRUE.
      ELSE IF (LINE(J+1:J+2).EQ.'UM') THEN
         L_MICRON=.TRUE.
      ELSE IF (LINE(J+1:J+2).EQ.'NM') THEN
         L_NANOMETRE=.TRUE.
      ELSE IF (LINE(J+1:J+4).EQ.'CM-1') THEN
         L_INVERSE_CM=.TRUE.
      ELSE
         WRITE(IU_ERR, '(/A)') '*** ERROR: ILLEGAL UNIT.'
         IERR=I_ERR_FATAL
         RETURN
      ENDIF
!
      N_FILTER=0
3     READ(IU_FILTER, '(A)') LINE
      IF (LINE(1:4).NE.'*END') THEN
         N_FILTER=N_FILTER+1
         BACKSPACE(IU_FILTER)
         READ(IU_FILTER, *, IOSTAT=IOS)
     &      WAVENUMBER_FILTER(N_FILTER), TRANS_FILTER(N_FILTER)
         IF (IOS.NE.0) THEN
            WRITE(IU_ERR, '(/A)') '** ERROR: UNREADABLE FILTER GIVEN.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
         GOTO 3
      ENDIF
!
!     CONVERT THE WAVENUMBERS TO INVERSE METRES.
      IF (L_METRE) THEN
         DO I=1, N_FILTER
            WAVENUMBER_FILTER(I)=1.0D+00/WAVENUMBER_FILTER(I)
         ENDDO
      ELSE IF (L_MICRON) THEN
         DO I=1, N_FILTER
            WAVENUMBER_FILTER(I)=1.0D+06/WAVENUMBER_FILTER(I)
         ENDDO
      ELSE IF (L_NANOMETRE) THEN
         DO I=1, N_FILTER
            WAVENUMBER_FILTER(I)=1.0D+09/WAVENUMBER_FILTER(I)
         ENDDO
      ELSE IF (L_INVERSE_CM) THEN
         DO I=1, N_FILTER
            WAVENUMBER_FILTER(I)=1.0D+02*WAVENUMBER_FILTER(I)
         ENDDO
      ENDIF
!
!
      RETURN
      END
