      SUBROUTINE MIXEDLAYERCHOICE(ivar,xgrad,xdel1,xdel2,
     * cmixname,nspmix)

C     MIXEDLAYERCHOICE CHOOSES MIXED LAYER CRITERIA
C     BASED ON USER INPUT

      parameter (maxchoice=20,icmax=20)
      character*16 firsttime
      character*80 filename,cmixname
      character*200 text
      dimension icomma(icmax,2)
 
      save firsttime
      save mixchoice
 
      if ( firsttime .ne. 'mixedlayerchoice' ) then
       firsttime='mixedlayerchoice'
       open(12,file='./mixedlayer_type',status='old',
     *  iostat=ios)
       if ( ios .eq. 0 ) then
        read(12,*) mixchoice
        close(12)
       else
        write(6,*) 'Enter mixed layer depth choice'
        read(5,*) mixchoice
       endif
      endif

      call clearstring(filename,80)
      call extraname('sys.inf'//CHAR(0),
     * 'mixed_layer_info.d'//CHAR(0),filename)
      open(12,file=filename,status='old')

      ifound=0
      read(12,'(a)') text
      do 30 nn=1,maxchoice
       call clearstring(text,200)
       read(12,'(a)',end=31) text
       call findlastchar(nsp,text,200)

       call spacefindl(nsp,icmax,ncomma,icomma,text)
       read(text(icomma(1,1):icomma(1,1)+icomma(1,2)-1),*)
     *  ichoice
       if ( mixchoice .eq. ichoice ) then 
        ifound=1
        read(text(icomma(2,1):icomma(2,1)+icomma(2,2)-1),*)
     *   ivar
        read(text(icomma(3,1):icomma(3,1)+icomma(3,2)-1),*)
     *   xgrad
        read(text(icomma(4,1):icomma(4,1)+icomma(4,2)-1),*)
     *   xdel1
        read(text(icomma(5,1):icomma(5,1)+icomma(5,2)-1),*)
     *   xdel2
        call clearstring(cmixname,80)
        cmixname=text(icomma(6,1):icomma(6,1)+icomma(6,2)-1)
        nspmix=icomma(6,2)
       endif
30    continue
31    continue
      close(12)
   
      if ( ifound .eq. 0 ) then
       write(6,*) 'Given choice:',mixchoice  
       write(6,*) 'Does not match any choices in mixed_layer_info.d'
      endif

      return
      end
