!!$
!!$=head1 NAME
!!$
!!$ Kirmod3d - Kirchoff modeling
!!$
!!$=head1 SYNOPSIS
!!$
!!$Kirmod3d par=parfile.P < Geom.H > output.H Green= Reflector= 
!!$    Wavelet= Green= [Ang_diff= Ang_surf= ]
!!$
!!$=head1 INPUT PARAMETERS
!!$
!!$=over 4
!!$
!!$=item   Stdin 
!!$
!!$        Contains sep3d headers of geometry to be modeled
!!$
!!$=item mode -integer 
!!$
!!$     =1 - kinematic  Isotropic scatterers (simpler, faster, default) 
!!$     =2 - dynamic    Uses Rayleigh scattering to get *approximately* correct
!!$     amplitudes.
!!$
!!$=item nt_data=(int)  
!!$
!!$      Number of time samples in modeled data
!!$
!!$=item dt_data=(real) 
!!$
!!$      Sample interval in modeled data
!!$
!!$=item t0_data=(real) 
!!$
!!$      First time to be modeled
!!$
!!$=item [ntr_block=(int)] 
!!$
!!$      Number of traces in each block
!!$
!!$=item [spow=1 (int)] 
!!$
!!$      Directivity of source !!! (not implemented)
!!$
!!$=item [rpow=1 (int)] 
!!$
!!$      Directivity of receiver !!! (not implemented)
!!$
!!$
!!$=item convolve_wave-int
!!$
!!$       =1 Convolve output with wavelet (default)
!!$       =0 Don't
!!$
!!$
!!$=item Wavelet -   sepfile
!!$
!!$       1D real sep77 file containing wavelet in time domain
!!$
!!$=item Reflector - 2D real sep77 file 
!!$
!!$  
!!$      kinematic: n1=4 (z,x,y,perturbation)
!!$      dynamic:   n1=6 (z,x,y,d_rho,d_lambda,d_mu)
!!$
!!$
!!$=item Green -     3D real sep77 file 
!!$
!!$      containing traveltimes & 
!!$      amplitudes (& angles) for 1D greens function
!!$      1-axis ... depth
!!$      2-axis ... offset
!!$      3-axis ... (:,:,1) = traveltimes
!!$      (:,:,2) = amplitudes
!!$      (:,:,3) = sin_theta_diff (dynamic only)
!!$      (:,:,4) = cos_theta_diff (dynamic only)
!!$      (:,:,5) = sin_theta_surf (dynamic only)
!!$      (:,:,6) = cos_theta_surf (dynamic only)
!!$
!!$=back
!!$
!!$=head1 DESCRIPTION
!!$
!!$ Born/Kirchhoff modeling program for sep3d
!!$ Needs Green's function tables supplied externally
!!$ See 'Modeling heterogeneous reservoirs using the first order Born 
!!$   Approximation', Rickett, Biondi & Lumley (SEP92)
!!$   for references on Born/Rayleigh scattering
!!$
!!$
!!$=head1 SEE ALSO
!!$
!!$
!!$L<Marine_geom3d> (for creating geometries)
!!$L<Gfgradz> (for creating Green's function tables)
!!$L<Scat3d> (for converting cube of scatterers to (x,y,z,ampl))
!!$L<Wavelet> (for making wavelets)
!!$
!!$
!!$=head1 KEYWORDS
!!$
!!$ born kirchhoff modeling modelling 3D sep3d avo amplitude
!!$
!!$
!!$=head1 CATEGORY
!!$
!!$B<seis/model>
!!$
!!$=cut
!!$
!>
!%%
!
! james 11/96
! Bob 9/99 Changed to superset interface

program Kirmod3D
  use sep3d_struct_mod
  use kirmod_mod
  implicit none
  type (sep3d) :: refl, headers, wavelet
  integer :: nsz

  call initpar ()
  call init_3d ()
call sep_add_doc_line("NAME")
call sep_add_doc_line("     Kirmod3d - Kirchoff modeling")
call sep_add_doc_line("")
call sep_add_doc_line("SYNOPSIS")
call sep_add_doc_line("    Kirmod3d par=parfile.P < Geom.H > output.H Green= Reflector= Wavelet=")
call sep_add_doc_line("    Green= [Ang_diff= Ang_surf= ]")
call sep_add_doc_line("")
call sep_add_doc_line("INPUT PARAMETERS")
call sep_add_doc_line("    Stdin")
call sep_add_doc_line("                Contains sep3d headers of geometry to be modeled")
call sep_add_doc_line("")
call sep_add_doc_line("    mode -integer")
call sep_add_doc_line("             =1 - kinematic  Isotropic scatterers (simpler, faster, default) ")
call sep_add_doc_line("             =2 - dynamic    Uses Rayleigh scattering to get *approximately* correct")
call sep_add_doc_line("             amplitudes.")
call sep_add_doc_line("")
call sep_add_doc_line("    nt_data=(int)")
call sep_add_doc_line("              Number of time samples in modeled data")
call sep_add_doc_line("")
call sep_add_doc_line("    dt_data=(real)")
call sep_add_doc_line("              Sample interval in modeled data")
call sep_add_doc_line("")
call sep_add_doc_line("    t0_data=(real)")
call sep_add_doc_line("              First time to be modeled")
call sep_add_doc_line("")
call sep_add_doc_line("    [ntr_block=(int)]")
call sep_add_doc_line("              Number of traces in each block")
call sep_add_doc_line("")
call sep_add_doc_line("    [spow=1 (int)]")
call sep_add_doc_line("              Directivity of source !!! (not implemented)")
call sep_add_doc_line("")
call sep_add_doc_line("    [rpow=1 (int)]")
call sep_add_doc_line("              Directivity of receiver !!! (not implemented)")
call sep_add_doc_line("")
call sep_add_doc_line("    convolve_wave-int")
call sep_add_doc_line("               =1 Convolve output with wavelet (default)")
call sep_add_doc_line("               =0 Don't")
call sep_add_doc_line("")
call sep_add_doc_line("    Wavelet - sepfile")
call sep_add_doc_line("               1D real sep77 file containing wavelet in time domain")
call sep_add_doc_line("")
call sep_add_doc_line("    Reflector - 2D real sep77 file")
call sep_add_doc_line("              kinematic: n1=4 (z,x,y,perturbation)")
call sep_add_doc_line("              dynamic:   n1=6 (z,x,y,d_rho,d_lambda,d_mu)")
call sep_add_doc_line("")
call sep_add_doc_line("    Green - 3D real sep77 file")
call sep_add_doc_line("              containing traveltimes & ")
call sep_add_doc_line("              amplitudes (& angles) for 1D greens function")
call sep_add_doc_line("              1-axis ... depth")
call sep_add_doc_line("              2-axis ... offset")
call sep_add_doc_line("              3-axis ... (:,:,1) = traveltimes")
call sep_add_doc_line("              (:,:,2) = amplitudes")
call sep_add_doc_line("              (:,:,3) = sin_theta_diff (dynamic only)")
call sep_add_doc_line("              (:,:,4) = cos_theta_diff (dynamic only)")
call sep_add_doc_line("              (:,:,5) = sin_theta_surf (dynamic only)")
call sep_add_doc_line("              (:,:,6) = cos_theta_surf (dynamic only)")
call sep_add_doc_line("")
call sep_add_doc_line("DESCRIPTION")
call sep_add_doc_line("     Born/Kirchhoff modeling program for sep3d")
call sep_add_doc_line("     Needs Green's function tables supplied externally")
call sep_add_doc_line("     See 'Modeling heterogeneous reservoirs using the first order Born ")
call sep_add_doc_line("       Approximation', Rickett, Biondi & Lumley (SEP92)")
call sep_add_doc_line("       for references on Born/Rayleigh scattering")
call sep_add_doc_line("")
call sep_add_doc_line("SEE ALSO")
call sep_add_doc_line("    Marine_geom3d (for creating geometries) Gfgradz (for creating Green's")
call sep_add_doc_line("    function tables) Scat3d (for converting cube of scatterers to")
call sep_add_doc_line("    (x,y,z,ampl)) Wavelet (for making wavelets)")
call sep_add_doc_line("")
call sep_add_doc_line("KEYWORDS")
call sep_add_doc_line("     born kirchhoff modeling modelling 3D sep3d avo amplitude")
call sep_add_doc_line("")
call sep_add_doc_line("CATEGORY")
call sep_add_doc_line("    seis/model")
call sep_add_doc_line("")

  call doc()

  write(0,*) 'Read parameters...'
  call init_modeling ()

  write(0,*) 'Reading model...'
  call init_sep3d('Reflector',refl,"INPUT")

  if ((mode == 1) .and. (refl%n(1) /= 4)) call seperr ('Err: Need model n1=4')
  if ((mode == 2) .and. (refl%n(1) /= 6)) call seperr ('Err: Need model n1=6')

  write(0,*) 'Reading geometry...'
  call init_sep3d ('in', headers,"INPUT")
  call sep3d_change_dims(headers%tag,2,(/1,headers%ndims/))
  call sep3d_grab_sep3d(headers%tag,headers)

  if (conv_wave == 1) then
     write(0,*) 'Reading wavelet...'
     call init_sep3d("Wavelet",wavelet,"INPUT")
  end if

  write(0,*) 'Allocating block...'
  call alloc_block (headers%ntraces)

  write(0,*) 'Reading greens functions...'
  call read_green ()

  write(0,*) 'Modeling data...'
  call kir_modeling (refl, headers, wavelet)

end program Kirmod3D

