***********************************************************
*     include file volpis3.inc
***********************************************************
      ! implicit none
      integer nmax,wmax,tmax,wmaxIBALLA,bmax
      ! nmax=zahl der spuren, wmax=pot 2, frequenzsamples
      ! tmax=zeitsamples
      parameter(nmax=250,wmax=1024,tmax=1024,tmax2=2048)
      parameter(bmax=200)
      ! vers.9 bmax=bootstrap loop
      !parameter(nmax=500,wmax=2048,tmax=2048)
      !parameter(wmaxIBALLA=4196)
      !parameter(wmaxIBALLA=50000)
      parameter(wmaxIBALLA=600000)   ! use same dim as c_sigsize !
 
      integer i,j,j1,j2,k,k0,k1,k2,kbeg,kneu,n,m,ifail
      integer*4 iout
      integer ione,ionel,iadd
      integer igreen,ibl,iscal,igame
      integer chinv,io,iom
 
      integer iso
      real xm0(6),xm0_old(6),xm1(6),mag
      real xi(3),xi1(3),dc,rm,pt(6)
 
      real*8 qp,qs,q,wnyq,tstar
      complex*16 carg
      
      real*8 xdifa1,xdifa2,xdifa3,xdifa4,xdifa5,xsynt
c     real*8 syntr,syntz,syntt,synts
      real*8 xm(6)
      real*8 ax,ay,dazi,dtoff,wfikt
      real*8 M0,D0,Phi,delta,lambda
      real*8 Phi1,delta1,lambda1
      common /source/xm,dazi,dtoff,ax,ay,wfikt,
     &         M0,D0,Phi,delta,lambda
 
      real*8 g(8),gIM(8)
      real*8 g0r(3),g0z(3),g0t(2)
      common /greenamp/g,gIM
 
c     real*8 gT(8),gTIM(8)
c     common /greenamp1/gT,gTIM
 
c     real*8 dat(nmax,3,tmax)
      real synth(tmax,nmax)
      real wsynth(tmax,nmax)
      real*8 sn,se,sz,slen
      real*8 dat(nmax,tmax),vkomp(nmax,5)
      real*8 gmats(8,tmax),gmats1(8,tmax)
      real*8 gmatsIM(8,tmax),gmats1IM(8,tmax)
      complex*8 cdat(nmax,wmax)
      common /greenmat/gmats,gmats1,gmatsIM,gmats1IM,dat,synth,
     &  vkomp,cdat,gmattim(nmax,9,tmax)
 
      complex*16 gmatfre(nmax,9,wmax/2+1)
c     complex*16 gmatfre(nmax,8,wmax)
      common /greenfreq/ gmatfre
 
      integer iw,ie,idip,istrike,irake,ngrid,ngrid1
      integer ngrid4,ngrid5,ngrid6
      integer ig,imodel,wi
      real*8 dgrid
      real*8 design(nmax*tmax,6),resid(nmax*tmax)
      integer it,info
      real x1,x2
      real*8 eps,epsa,epsb,epsnorm,cost,costlist(20)
      real wt(nmax)
      real*8 work(2*nmax*tmax)
      common /residuals/ design,resid,epsnorm,wt,it
 
      character*1 cdummy
      character*143 csolution,cbest(20)
      integer mdeck,idummy,nlay,i1,i2,i3,l
      real*8 sv(3),nv(3),bv(3)
 
      real*8 pi,rad
C     real*8 alpha,beta,rho
      real*8 eta,mu
      real*8 vel(nmax)
      real*8 cr(3,3,3),cT(3),cL(3),cW(3)
      complex ci,cs
c     common/static/ci,pi,rad,alpha,beta,rho
      common/static/ci,pi,rad,vel,mu,eta
      
      integer itmax
      real*8 fa,fb
      common/geom3/fa,fb,itmax,igame
 
      real*8 sl,sw,vr,dts,trup,trise,trise1,strike,dip,rake
      common/geom1/sl,sw,vr,dts,trup,trise,trise1,strike,dip,
     & rake
      real*8 xmom,dxmom
      common/higher/dxmom,xmom
       
      integer nstat,nstatl,nstat1
      integer istat(nmax),nstatc(8)
      integer lx,lxx,isamp(nmax),isampf,itmp,isyn
      integer lx0
      integer lxl,lxxl,ix,ixx,isampfl
      integer iretard(nmax),iretardg(nmax)
      !integer iretard1(nmax)
      real tap, tapl
      real fc,fcu,fcl,fcul
      real dtr
      real*8 fscal
      real*8 dt,dw,dtl
      real*8 r,az
      real*8 re(nmax),azi(nmax)
      real*8 vsh,vsv,vp,gr,gz,gt,gsv,gsh,gp
      real*8 toff(nmax)
c     common/geom2/fscal,dt,dtl,r,re,azi,toff,fc,fcu,nstat,lx,lxx,
c    & lxl,lxxl,ix,ixx,isamp,isyn,iretard,iretard1
      common/geom2/fscal,dt,dtl,r,re,azi,toff,fc,fcu,nstat,lx,lxx,
     & lxl,lxxl,ix,ixx,isamp,isyn,iretard
      
      integer komp,ifreq(nmax),ikomp(nmax)
      !integer iballa(wmaxIBALLA)
      !character*1 cbuf(c_bufsize)
      integer iss2(16),iss3(15),iss4(20)
      real wmom,w,bal,balmax,abal
      integer ibal
      integer ifen(nmax,tmax),ifenl
      real filt(wmax),filtl(wmax)
      real*8 x0
C     real*8 sb(nmax,3)
      real*8 sa(nmax,3)
c     common /slowness/ sa,sb
      common /slowness/ sa
 
      real amin,amax
      
C     complex*16 u(wmax,3)
      
      complex*8 cx(wmax),cx1(wmax),ccx(wmax)
ccc v6      common/feld1/ cx,cx1,ccx
c     integer ifil(8),ifil0(5)
      integer ifil(8)
      !character*10 cfil0(8)
      character*11 cfil0(8)
      character*5 cfil2(45)
      character*38 cfil2a(45)
      character*36 cfil(nmax)
      character*1 comp(nmax)
      character*8 cphas(nmax)
      character cdir*26,char3*4,cinput*35
      common/output/ cfil,cfil0
 
      complex*16 uw(nmax),gw(nmax,9),gwt(9,nmax),mw(9),hw(19,18)
      complex*16 nonimp(9),bvect(9),dete(2),hwi(9,9),hws(9,9)
      complex*16 gwi(9,nmax),sourfre(9,wmax),sfre(nmax)
      complex*16 syntfre(nmax,wmax)
      complex*8  fdat(nmax,wmax),csourtim(wmax),dhelp(wmax)
      real*8     sourtim(9,tmax),synttim(nmax,tmax)
      real*8     mtc(tmax),sfc(tmax),mfc(tmax)
      real*8     snum,sdet,sabs
      real*8     fildat(nmax,tmax)
      integer    nfpar,dimmat,ipiv(18)
      double precision deven
      real*8     misf,misfterm,dddmax(nmax),mismax,misf2
      real*8     misfitfm,misfitcom
      integer    ddd(nmax,tmax)
      integer    ifr
      character*20 filesy,fileda

c     version 4
      double precision amat(tmax,tmax),bmat(tmax,tmax),svet(tmax)
      double precision weimat(tmax,tmax),vtmat(tmax,tmax)
      double precision umat(tmax,tmax),wsvd(tmax2),stf(tmax)
      double precision smat(tmax,tmax),coms(tmax,9)
      double precision num(9),den(9)
      double precision stff(tmax),stfm(tmax),stfc(tmax)
      real*8 misft2,misfc,misffm,sourek(9),sourekm,sourekf
      integer    mda,m1,n1,mdb,mb

c     version 6
      complex*8  cx6(wmax)
      real*8     hfkt(tmax)
      complex*8 sfun(9,tmax),confun(9,tmax)
      real*8    confunr(9,tmax)
      real    hfktlen,winlen
      integer v6i,idp,istr
      double precision v6istf,v6str,v6dip,v6mu,v6lam,v6rak
      double precision v8m(6),v6fmod
      double precision v6f1,v6f2,v6f3
      double precision rza(3,3),rxb(3,3),rzg(3,3)
      double precision ry45(3,3),rbet(3,3)
      double precision xm0d(3,3),xm1d(3,3),rhilf(3,3),scalf
      double precision xf1d(3),scalmom
      double precision misnum,misden,misnum2,misden2
      character*20   fileforw
      character*3    cstr
      character*2    cdp
      real*8         synmf(nmax,tmax),syncom(nmax,tmax)
      real*8         syntforw(nmax,tmax)

c     version9
      complex*16 gwiw(wmax,9,nmax)
      double precision eter(wmax),etei(wmax)  
      double precision deltam(9,wmax),rdeltam(9,wmax),ideltam(9,wmax)
      real*8     rvaluem(9,wmax),ivaluem(9,wmax)    
      double precision tempmr,tempir,tempm(9,wmax)
      integer    iboot,wsing(wmax),jgas
      double precision ttsourtim(bmax,9,tmax)
      complex*8  ttcsourtim(wmax),pasval
      real       meanboot(9,tmax),sdevboot(9,tmax)
 
      common/feld1/ cx,cx1,ccx,cx6
