!!.. this module defines all the global variables
!!.. that are shared by all the subroutines and functions
module wei_global_defi_mod
  use wei_type_mod
  implicit none

  type(dat_grid)   , save 							:: dgrid    ! data grid 
  type(vel_grid)   , save 							:: vgrid    ! velocity grid
  type(pro_grid)   , save 							:: pgrid    ! propagation grid
  type(img_grid)   , save 							:: igrid    ! image grid
  type(out_grid)   , save 							:: ogrid    ! image output grid
  type(gre_grid)   , save 							:: ggrid    ! green's function grid

  type(block)      , save 							:: zblock
  type(block)      , save 							:: wblock


  !real, allocatable, dimension(:,:,:)    , target, save 			:: vmod      ! input velocity model for depth nzs
  !real, allocatable, dimension(:,:)      , target, save 			:: vref      ! reference velocity for depth nzs
  real, dimension(:,:,:), pointer, save 					:: vmod
  real, dimension(:,:)  , pointer, save 					:: vref

  real, dimension(:), pointer        , save 					:: kx2               ! wavenumber kx*kx
  real, dimension(:), pointer        , save 					:: ky2               ! wavenumber ky*ky

  !real, allocatable, dimension(:,:,:,:,:), target, save 			:: model     ! final image for depth nzs
  !real, allocatable, dimension(:,:,:,:,:), target, save 			:: normd     ! shot illumination map
  real, dimension(:,:,:,:,:), pointer, save 					:: model
  real, dimension(:,:,:,:,:), pointer, save 					:: normd
  !complex, allocatable, dimension(:,:), save 					:: crec   ! input receiver gather (in freq domain, nws)
  !complex, allocatable, dimension(:)  , save 					:: csou   ! input source function (in freq domain, nws)
  complex, dimension(:,:), pointer, save 					:: crec
  complex, dimension(:)  , pointer, save 					:: csou
  !complex, allocatable, dimension(:,:,:), target, save 			:: wfld_d ! downward wavefield in propagation grid
  !complex, allocatable, dimension(:,:,:), target, save 			:: wfld_u ! upward wavefield in propagation grid
  complex, dimension(:,:,:), pointer, save 					:: wfld_d
  complex, dimension(:,:,:), pointer, save 					:: wfld_u

  logical, save 								:: lloyd
  logical, save 								:: decon
  logical, save 								:: radian
  logical, save 								:: offset
  logical, save 								:: adj
  logical, save 								:: taper
  logical, save 								:: true_ampli
  logical, save 								:: greens
  logical, save 								:: wfld_d_out
  logical, save 								:: wfld_u_out
  real   , save 								:: taper_pct
  real   , save 								:: eps
  real   , save 								:: maxang
  integer, save 								:: hessian_type
  integer, save 								:: taper_type
  integer, save 								:: nref
  integer, save 								:: num_report
  integer, save 								:: istep
  integer, save 								:: rstep
  integer, save 								:: astep
  integer, save 								:: nstep
  
  character(len=256), save 							:: sou_, rec_, vel_, img_
  character(len=256), save 							:: wfld_d_, wfld_u_
  character(len=256), save 							:: hdr_sou_, hdr_rec_
  character(len=256), save 							:: hessian_, greens_, datumn_


  real   , parameter 								:: PI = 3.14159265359
  logical, parameter 								:: T = .true.
  logical, parameter 								:: F = .false.
  integer, save      								:: memory
end module
