anchor.diff:           call sw_error('sw_misfit_ecs: Output array for dt_ecs is too small')
      endif
   
  -   allocate(phi2(n), dt2(n))
  +   call sw_alloc(phi2,n)
  +   call sw_alloc(dt2,n)
   
      ! Calculate splitting and misfit for each observation
      do i=1,n
  
positive.code:    N%f = 4.0/freq_in ; N%user2 = N%f ; N%user3 = N%f + delta_in
     E%f = 4.0/freq_in ; N%user2 = E%f ; N%user3 = E%f + delta_in
     Z%f = 4.0/freq_in ; Z%user2 = N%f ; Z%user3 = Z%f + delta_in
  
     deallocate(trace)
  
  end subroutine sw_create_wave
  !------------------------------------------------------------------------------
  
negative.code: !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc1r4(var, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r4), intent(inout), allocatable, dimension(:) :: var
     integer, intent(in) :: n
     if (allocated(var)) then
        if (size(var) /= n) then
           deallocate(var)
           allocate(var(n))
        endif
     else
        allocate(var(n))
     endif
  end subroutine sw_alloc1r4
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc2r4(var, m, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r4), intent(inout), allocatable, dimension(:,:) :: var
     integer, intent(in) :: m, n
     if (allocated(var)) then
        if (size(var, 1) /= m .or. size(var, 2) /= n) then
           deallocate(var)
           allocate(var(m,n))
        endif
     else
        allocate(var(m,n))
     endif
  end subroutine sw_alloc2r4
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc3r4(var, l, m, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r4), intent(inout), allocatable, dimension(:,:,:) :: var
     integer, intent(in) :: l, m, n
     if (allocated(var)) then
        if (size(var, 1) /= l .or. size(var, 2) /= m .or. size(var, 3) /= n) then
           deallocate(var)
           allocate(var(l,m,n))
        endif
     else
        allocate(var(l,m,n))
     endif
  end subroutine sw_alloc3r4
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc1r8(var, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r8), intent(inout), allocatable, dimension(:) :: var
     integer, intent(in) :: n
     if (allocated(var)) then
        if (size(var) /= n) then
           deallocate(var)
           allocate(var(n))
        endif
     else
        allocate(var(n))
     endif
  end subroutine sw_alloc1r8
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc2r8(var, m, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r8), intent(inout), allocatable, dimension(:,:) :: var
     integer, intent(in) :: m, n
     if (allocated(var)) then
        if (size(var, 1) /= m .or. size(var, 2) /= n) then
           deallocate(var)
           allocate(var(m,n))
        endif
     else
        allocate(var(m,n))
     endif
  end subroutine sw_alloc2r8
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_alloc3r8(var, l, m, n)
  !===============================================================================
  !  (Re)allocate a variable if not the correct size
     implicit none
     real(r8), intent(inout), allocatable, dimension(:,:,:) :: var
     integer, intent(in) :: l, m, n
     if (allocated(var)) then
        if (size(var, 1) /= l .or. size(var, 2) /= m .or. size(var, 3) /= n) then
           deallocate(var)
           allocate(var(l,m,n))
        endif
     else
        allocate(var(l,m,n))
     endif
  end subroutine sw_alloc3r8
  !-------------------------------------------------------------------------------
  
  !===============================================================================
  subroutine sw_error(str)
  !===============================================================================
     implicit none
  