!+ Subroutine to open a file of averaged scattering data for output.
!
! 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 OPEN_AVERAGE(IERR, L_WRITE)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_sct_io.icf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY VARIABLES.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      LOGICAL	!, INTENT(OUT)
     &     L_WRITE
!             WRITING FLAG
!
!     LOCAL VARIABLES.
!
      LOGICAL
     &     LOCK_CODE
!             LOGICAL TO FORBID INTERACTIVE LOOPING
      EXTERNAL
     &     LOCK_CODE
!
      CHARACTER
     &     CHAR_YN
!             RESPONSE VARIABLE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_FILE_OUT
!
!
!
!     DETERMINE WHETHER OUTPUR FOR EACH BLOCK IS REQUIRED.
      WRITE(IU_USER, '(/A)') 'DO YOU WISH TO PRINT THE AVERAGED '
     &   //'SCATTERING PROPERTIES FOR EACH BLOCK? (Y/N)'
      WRITE(IU_USER, '(A)') 'THIS MUST BE SELECTED FOR AEROSOLS.'
1     READ(IU_STDIN, '(A)') CHAR_YN
      IF ( (CHAR_YN.EQ.'N').OR.(CHAR_YN.EQ.'n') ) THEN
         L_WRITE=.FALSE.
         RETURN
      ELSE IF ( (CHAR_YN.NE.'Y').AND.(CHAR_YN.NE.'y') ) THEN
         WRITE(IU_ERR, '(A)') '+++ ILLEGAL RESPONSE:'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error.finc'
         ELSE
            WRITE(IU_USER, '(A)') 'PLEASE RE-TYPE.'
            GOTO 1
         ENDIF
      ENDIF
!
!     SET THE WRITING FLAG TO TRUE: THIS WILL BE CHECKED AS EACH BLOCK
!     IS AVERAGED.
      L_WRITE=.TRUE.
!
      CALL OPEN_FILE_OUT(IERR, IU_AVERAGE
     &   , 'GIVE THE NAME OF THE FILE TO CONTAIN THE '
     &   //'AVERAGED SCATTERING DATA.')
      IF (IERR.NE.I_NORMAL) RETURN
!
!
      RETURN
      END
