# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
module err_shared_mod
  use sep3d_struct_mod
  use basic_util_mod
  implicit none
  contains
  logical function get_err_fields(semb_tag,semb,coher_tag,coher,err_space&
    &)
    character(len=*) :: semb_tag,coher_tag
    real, pointer :: semb(:,:,:),coher(:,:,:)
    type(sep3d) :: err_space,junk
    integer :: n(3)
    real :: o(3),d(3)
    integer, external :: auxin
    get_err_fields=.false.
!READ IN THE BEST RATIO (eventually internal)
    if (-1.eq.auxin(semb_tag)) then
      write(0,*) "        ERROR: getting semb_tag file=",trim(semb_tag&
        &)
      return
    end if
    call auxclose(semb_tag)
    call init_sep3d(semb_tag,err_space,"INPUT")
    call set_n_o_d_3d(err_space,n,o,d)
    allocate(semb(n(1),n(2),n(3)))
    allocate(coher(n(1),n(2),n(3)))
!READ IN THE SEMBLANCE AT EACH LOC (eventually internal)
    if (-1.eq.auxin(coher_tag)) then
      write(0,*) "        ERROR: getting coher_tag file",trim(coher_tag&
        &)
      return
    end if
    call auxclose(coher_tag)
    call init_sep3d(coher_tag,junk,"INPUT")
    if (.not. sep3d_conform(err_space,junk)) then
      write(0,*)err_space%n," =n (coher) (err)=n",junk%n
      write(0,*)err_space%o," =o (coher) (err)=o",junk%o
      write(0,*)err_space%d," =d (coher) (err)=d",junk%d
      write(0,*) trim(semb_tag),"=semb_tag coher_tag",trim(coher_tag)
      write(0,*) "        ERROR: ratio and semb_resid must be equal&
        & spaces"
      return
    end if
    if (.not. sreed_field(coher_tag,coher)) then
      write(0,*) "        ERROR: reading in coher_tag=",trim(coher_tag&
        &)
      return
    end if
    if (.not. sreed_field(semb_tag,semb)) then
      write(0,*) "        ERROR: reading in semb tag=",trim(semb_tag)
      return
    end if
    get_err_fields=.true.
  end function
end module
