anchor.diff:      i = index(input_line,trim(ch))
       input_line(1:i+len(trim(ch))) = ''
   enddo
  +
  +return
  +end subroutine
  +
  +!--------------------------------------------------------------------------------------------------!
  +
  +subroutine read_header(nit,nflt,npoles,log_format)
  +
  +use io, only: stderr, stdout
  +
  +use anneal_post, only: lu_log_file, &
  +                       burnin_iterations
  +
  +implicit none
  +
  +! Arguments
  +integer :: nit, nflt, npoles
  +character(len=*) ::  log_format
  +
  +! Local variables
  +logical :: continueReadingHeader
  +integer :: i, ios
  +character(len=512) :: input_line
  +
  +
  +! Set search variables before reading
  +nit = 0
  +nflt = 0
  +npoles = 0
  +log_format = ''
  +
  +
  +! Initialize to continue reading header
  +continueReadingHeader = .true.
  +
  +
  +do while (continueReadingHeader)
  +
  +    read(lu_log_file,'(A)',end=4001,iostat=ios) input_line
  +
  +    ! All header lines start with a "#" in the first character and have the format:
  +    !     # label1=value1 label2=value2 ...
  +    ! Where "label" describes a parameter, and "value" is a number or string for the parameter
  +
  +    if (index(input_line,'#').ne.1) then
  +        ! Not a header line; finished parsing header
  +        continueReadingHeader = .false.
  +        backspace(lu_log_file)
  +
  +    else
  +
  +        ! Found header line; parse parameter and value
  +        if (index(input_line,'niterations').ne.0) then
  +            i = index(input_line,'=')
  +            input_line(1:i) = ''
  +            read(input_line,*) nit
  +
  +        elseif (index(input_line,'nfaults').ne.0) then
  +            i = index(input_line,'=')
  +            input_line(1:i) = ''
  +            read(input_line,*) nflt
  +
  +        elseif (index(input_line,'npoles').ne.0) then
  +            i = index(input_line,'=')
  +            input_line(1:i) = ''
  +            read(input_line,*) npoles
  +
  +        elseif (index(input_line,'format').ne.0) then
  +            i = index(input_line,'=')
  +            input_line(1:i) = ''
  +            read(input_line,*) log_format
  +
  +        else
  +            write(stderr,*) 'anneal_log: read header line:',trim(input_line)
  +            call usage('But could not parse a parameter')
  +        endif
  +
  +    endif
  +
  +enddo
  +
  +4001 if (ios.ne.0) then
  +    call usage('anneal_post: reached end of file in header section')
  +endif
  +if (nit.le.burnin_iterations) then
  +    call usage('anneal_post: number of burn-in iterations is greater than total iterations')
  +endif
  +
  +if (nit.eq.0) then
  +    call usage('anneal_post: read zero iterations in log file')
  +endif
  +if (nflt.eq.0) then
  +    call usage('anneal_post: read zero faults in log file')
  +endif
  +
  +write(stdout,*) 'anneal_post: finished parsing header'
  +write(stdout,*) 'niterations=',nit
  +write(stdout,*) 'nfaults=',nflt
  +write(stdout,*) 'npoles=',npoles
  +write(stdout,*) 'log_format= ',log_format
   
   return
   end subroutine
  
positive.code: 
      elseif (log_format.eq.'anneal_psc') then
          do iflt = 1,nflt
              read(21,'(A)',end=1002,iostat=ios) input_line
              if (it.gt.0) then
                  read(input_line,*,end=1003,err=1003,iostat=ios) locked(it,iflt), slip(it,iflt,1:2)
              endif
  
negative.code: endif
  
  ! Open the log file
  lu_log_file = 21
  open(unit=lu_log_file,file=anneal_log_file,status='old')
  
  
  !----
  ! Read annealing log file
  !----
  ! Parse log file header
  call read_header(nit,nflt,npoles,log_format)
  
  
  ! Set up arrays
  