c======================================================================
c     SPELLING CHECKER
c
c     This spelling checker is based on the SPELL utility of the LBL
c     software  tools.    It  uses  three  dictionaries  (a  common,
c     a project and a user defined dictionary).
c
c======================================================================

      implicit none

      include 'spell_include'

      character*132  filename
      integer*4      length,unit
      logical*4      get_command_line_parameter
      logical*4      load_common_dictionary
      logical*4      load_project_dictionary
      logical*4      load_user_dictionary
      logical*4      common_flag
      logical*4      project_flag
      logical*4      user_flag

c     get command line parameters

      if (.NOT. get_command_line_parameter(length,filename)) then
            write (*,1000)
            read  (*,1001) length,filename
            if (length.eq.0) goto 999
      end if

c     open text file to be spell checked

      open (unit=7,file=filename,READONLY,err=100,status='OLD')

c     read common dictionary

      common_flag = load_common_dictionary()

      if (.NOT. common_flag) goto 110

c     load project dictionary

      project_flag = load_project_dictionary()

c     load user dictionary

      user_flag = load_user_dictionary()

c     display warning messages

      if ((.NOT. project_flag) .and. (.NOT. user_flag)) then
         write (*,1100)
      else if (.NOT. project_flag) then
         write (*,1110)
      else if (.NOT. user_flag) then
         write (*,1120)
      end if

c     spell check the text file
      
      unit = 7

      call spell_check_file (unit,common_flag,project_flag,user_flag)

      goto 999

c     error mesages

100   type *,'Error opening text file ',filename(1:length)
      goto 999

110   type *,'Error opening common dictionary'
      goto 999

c     end of program

999   close(unit=8)
      close(unit=9)

1000  format (/,' Enter text file to be checked : ',$)
1001  format (q,a)
1100  format (/,
     x ' Warning - Project and user dictionares are not available'//)
1110  format (/,
     x ' Warning - Project dictionary is not available'//)
1120  format (/,
     x ' Warning - User dictionary is not available'//)

      end
