module type_mod
  !! WEI type definitions
  implicit none

!---------------------------------------------------------------- 
  type axis
     integer          :: n=1,j=1,b=1
     real             :: o=0.,d=1.
     character(len=10):: l='blank'    !! label (i.e. axis name)
  end type axis
!----------------------------------------------------------------
  type slow_comp
     character(len=128) :: tag
     character(len=128) :: from="history"
     integer            :: bites=1,esize=4
     type(axis)         :: amx,amy,az
     integer :: indx=1,indy=1,finy=1,finx=1
     !! block binary array
     real, dimension(:,:,:),pointer :: bin !slowness (mx,my,z)
  end type slow_comp
!----------------------------------------------------------------
  type slow 
   type(slow_comp) :: s_r,s_s
   !! never allocated pointer to component velocity model binaries
   real, dimension(:,:,:),pointer :: bin !slowness (mx,my,z)
  end type slow 
!----------------------------------------------------------------
  type dat
     character(len=128) :: tag
     character(len=128) :: from="history"
     integer            :: bites=1
     integer            :: indx=1,indy=1 !!start index to insert into work space
     integer            :: finx=1,finy=1 !!indx + amx%n -1
     integer            :: esize=8
     type(axis)         :: amx, amy, asx, asy, aw !!input axes
     !! block binary array
     complex, dimension(:,:,:), allocatable  :: bin

  end type dat
!----------------------------------------------------------------
  type imag
     character(len=128) :: tag
     character(len=128) :: from="parameter"
     integer            :: bites
     integer            :: esize=4
     integer            :: indx=1,indy=1,finx=1,finy=1
     type(axis)         :: amx,amy,ahx,ahy,az,aw

     !! block binary array
     complex, dimension(:,:,:,:,:), allocatable :: bin
  end type imag
!----------------------------------------------------------------
  type twfld
     character(len=128) :: tag
     character(len=128) :: from="parameter"
     integer            :: bites=1
     type(axis)         :: amx,amy,aw,asx,asy,az
  end type twfld
!----------------------------------------------------------------
  type tkmap
     real,    dimension(:),allocatable :: kx,ky
  end type tkmap
!----------------------------------------------------------------
  type txmap
     real,    dimension(:),allocatable :: mx,my
     complex, dimension(:),allocatable ::s
  end type txmap
!----------------------------------------------------------------
  type slowmapthread
     integer, dimension(:,:,:),pointer :: si      !! f(mx,my,z)
     integer, dimension(:)    ,pointer :: nrs     !! f(z)
     real,    dimension(:,:)  ,pointer :: sz,bound
     logical :: source=.true.
  end type slowmapthread
!----------------------------------------------------------------
  type slowmap
     !! FKop slowness
     real,    dimension(:, :) ,pointer :: sz_s,sz_r,sz,bound,bound_r,bound_s !! f(z,nfk)
     !! Number of reference slownesses
     integer, dimension(:)    ,pointer :: nrs,nrs_s,nrs_r  !! f(z)
     !! FXop slowness interpolation map
     integer, dimension(:,:,:),pointer :: si        !! f(mx,my,z)
     integer, dimension(:,:,:),pointer :: si_r      !! f(mx,my,z)
     integer, dimension(:,:,:),pointer :: si_s      !! f(mx,my,z)
     logical :: source=.true.
  end type slowmap
!----------------------------------------------------------------
  type trun
     integer            :: verb=5  !! verbosity
     logical            :: debug=.false.!! Debug
     logical            :: depar=.false.!! debug in the parallel regions
     logical            :: omp=.false.  !! is an omp job? 
     logical            :: lock=.false.!! lock files before I/O
     integer            :: io=0    !! unit to write out verb info 
     integer            :: o_nth=1 !! number of omp threads
     integer            :: o_ith=1 !! omp thread number
     character(len=128) :: operation='migration',file_out='SCREEN'
  end type trun
!----------------------------------------------------------------
  type tdown
     logical:: adj, add
     integer:: opsign
     logical:: badsign !! bad FFT sign so I change it for you
     !! opsign=goT2B (e.g. migration)
     !! opsign=goB2T (e.g.  modeling) [never used]

     integer:: shotnum=0 !! shotcounter
     integer:: nx_shots=1,ny_shots=1  !! total shots (for Parallel)
     real   :: ox_shots=0.,oy_shots=0.!! total shots (for Parallel)
     real      :: scale!! scale the data
     real      :: mem  !!memory counter
     real   :: maxang=50.!! max prop. angle (zeros lookup table after)[currently off]

     !!blocking and memory management
     integer:: nws     !! number of frequency slices in a block (mem. management)
     integer:: wblock  !! nws can change, wblock will not
     integer:: nzs     !! number of depth slices in a block (mem. management)
     integer:: zblock  !! nzs can change, zblock will not
     integer:: firstz  !! first depth index to image
     integer:: firstzW !! first depth index to save wavefield 

     !! velocity possibilities
     integer:: nref=1       !! number of reference velocities
     logical:: cwave=.false.!! converted wave velocity
     logical:: vel=.false.  !! velocity or slowness?

     !! presence of io files
     logical:: gathers=.false. !! gathers (D) present
     logical:: sourcefn=.false.!! source (D_d) present
     logical:: mult=.false.    !! multiple modeling at imaging condition
     logical:: image=.false.   !! output image?
     logical:: normd=.false.   !! make DD*?
     logical:: wIOu=.false.    !! writing wavefields?
     logical:: wIOd=.false.    !! writing wavefields?
     logical:: headD_d=.false. !! header locations for sources
     logical:: headD =.false.  !! header locations for traces
     logical:: xyr=.false.     !! reverse xy order of headers

     !! operations
     logical:: fwdscat=.false. !! forward scattering migration
     logical:: passive=.false. !! passive seismic ShotProfile migration
     logical:: modelplane=.false.!! reflection from a plane as the source function (see D.F90 line 1211)
     logical:: datum=.false. !! only datuming gathers
     logical:: green=.false. !! only datuming source functions
     logical:: image_freqs=.false.!! write image as function of freqs
     logical:: image_real=.true.  !! write image as real or complex
     logical:: validshot=.true. !! dont do imaging and extraps if shot in taper zone

     !! fk mute
     logical:: antion=.false.!! apply antialiasing?
     real   :: pmin_y,pmax_y !! antialias limits
     real   :: pmin_x,pmax_x 

     !! acquisition geometry and axes
     logical:: offset!! receivers defined as offset from shot or real earth position
     logical:: roll  !! moving acquisition patch or same workspace for each shot
     logical::  watercolumn!! redatum thru water column
     type(axis):: awtr    !! zaxis for water column datum
     real      :: tshift  !! apply a FD time shift to source function
     type(axis):: amx,amy !! receiver axes
     type(axis):: ax,ay   !! imaging axes
     type(axis):: asx,asy !! shot axes
     type(axis):: ahx,ahy !! offsets computed in imaging condition
     type(axis):: aix,aiy !! total image from all shots
     type(axis):: az,bz   !! total depth, depth blocks
     type(axis):: aw,bw   !! total frequency, frequency blocks
     type(axis):: fatx,faty!!spatial thickness of source function (same as amx)
     type(axis)::trc,evnt !! traces past in HD, nsx*nsy

     !! decon imaging condition
     logical::dcnv=.false.    !!devide by DD* before frequency sum 
     logical::smoothme=.false.!!smooth first?
     real   ::eps=0.0001      !! if DD* .lt. eps 1/DD*=1. 
     integer::rect1=2,rect2=2 !! halfwidth on 1- 2- (1 means no smoothing) 

     !! tapers wavefield edges to minimize boundary effects
     logical::taperme=.true.  !! taper 
     integer::minx1,maxx1,miny1,maxy1 !! traces from begin/end of wfld for cos taper

     type(slow)        :: S       !! slowness
     character(len=128):: VS,VR,D,D_d,R,U,W,W_d,M,N_u,N_d,HD,HD_d !! file tags
     character(len=128):: mod_,dat_,dat_d_,m_,n_u_,n_d_,w_,w_d_,h_d_,h_d_d_
  end type tdown
!----------------------------------------------------------------
end module type_mod
