コード例 #1
0
ファイル: bft.c プロジェクト: JOravetz/SeisUnix
main()
{
	int npoles,nfft,i;
	float f3db,zero=0.0,fpass,apass,fstop,astop;

/*
	printf("Enter npoles f3db:\n");
	scanf("%d %f",&npoles,&f3db);
*/
	printf("Enter fpass apass fstop astop:\n");
	scanf("%f %f %f %f",&fpass,&apass,&fstop,&astop);
	bfdesign(fpass,apass,fstop,astop,&npoles,&f3db);
	printf("npoles = %d  f3db = %f\n",npoles,f3db);

	/* impulse response */
	scopy(N,&zero,0,p,1);
	p[0] = 1.0;
	bflowpass(npoles,f3db,N,p,q);
	pp1d(stdout,"impulse response",N,0,q);

	/* amplitude spectrum */
	nfft = npfa(N);
	for (i=0; i<N; i++)
		z[i] = cmplx(q[i],0.0);
	for (i=N; i<nfft; i++)
		z[i] = cmplx(0.0,0.0);
	pfacc(1,nfft,z);
	for (i=0; i<nfft; i++)
		zamp[i] = fcabs(z[i]);
	pp1d(stdout,"amplitude spectrum",nfft/2+1,0,zamp);
}
コード例 #2
0
void CIIRfilter::butter_poles(complex *p, char *type, int *n, int iord )
	{
	double	pi, angle;
	int	half, k;

        pi=M_PI;
        half = iord/2;

	/* test for odd order, and add pole at -1 */

        *n = 0;
        if (    2*half < iord )
			{
			p[0] = cmplx( -1., 0. );
			type[0] = 'S';
			*n = 1;
			}
	for (k = 0; k < half; k++)
		{
		angle = pi * ( 0.5f + (double)(2*(k+1)-1) / (double)(2*iord) );
		p[*n] = cmplx( (double)cos((double)angle), 
			(double)sin((double)angle) );
		type[*n] = 'C';
		*n = *n + 1;
		}
}
コード例 #3
0
ファイル: density_half.c プロジェクト: erinaldi/milc_qcd
/* do measurements: load density, ploop, etc. and phases onto lattice */
void measure() {
   register int i,j,k, c, is_even;
   register site *s;
   int dx,dy,dz;	/* separation for correlated observables */
   int dir;		/* direction of separation */
   msg_tag *tag;
   register complex cc,dd;	/*scratch*/
   complex ztr, zcof, znum, zdet, TC, zd, density, zphase;
   complex p[4]; /* probabilities of n quarks at a site */
   complex np[4]; /* probabilities at neighbor site */
   complex pp[4][4]; /* joint probabilities of n here and m there */
   complex zplp, plp_even, plp_odd;
   Real locphase, phase;


   /* First make T (= timelike P-loop) from s->ploop_t 
      T stored in s->tempmat1
   */
   ploop_less_slice(nt-1,EVEN);
   ploop_less_slice(nt-1,ODD);

   phase = 0.;
   density = plp_even = plp_odd = cmplx(0.0, 0.0);
   for(j=0;j<4;j++){
	p[j]=cmplx(0.0,0.0);
	for(k=0;k<4;k++)pp[j][k]=cmplx(0.0,0.0);
   }
   FORALLSITES(i,s) {
      if(s->t != nt-1) continue;
      if( ((s->x+s->y+s->z)&0x1)==0 ) is_even=1; else is_even=0;
      mult_su3_nn(&(s->link[TUP]), &(s->ploop_t), &(s->tempmat1));

      zplp = trace_su3(&(s->tempmat1));
      if( is_even){CSUM(plp_even, zplp)}
      else        {CSUM(plp_odd, zplp)}

      ztr = trace_su3(&(s->tempmat1));
      CONJG(ztr, zcof);

      if(is_even){
        for(c=0; c<3; ++c) s->tempmat1.e[c][c].real += C;
        zdet = det_su3(&(s->tempmat1));
        znum = numer(C, ztr, zcof);
        CDIV(znum, zdet, zd);
        CSUM(density, zd);

        /* store n_quark probabilities at this site in lattice variable
	  qprob[], accumulate sum over lattice in p[] */
        cc= cmplx(C*C*C,0.0); CDIV(cc,zdet,s->qprob[0]); CSUM(p[0],s->qprob[0]);
        CMULREAL(ztr,C*C,cc); CDIV(cc,zdet,s->qprob[1]); CSUM(p[1],s->qprob[1]);
        CMULREAL(zcof,C,cc); CDIV(cc,zdet,s->qprob[2]); CSUM(p[2],s->qprob[2]);
        cc = cmplx(1.0,0.0); CDIV(cc,zdet,s->qprob[3]); CSUM(p[3],s->qprob[3]);
  
        locphase = carg(&zdet);
        phase += locphase;
      }

   }
コード例 #4
0
ファイル: relax.c プロジェクト: erinaldi/milc_qcd
void relax(int NumStp)
{
  /* Do overrelaxation by SU(2) subgroups */
int NumTrj, Nhit, index1, ina, inb, ii;
int subl;
Real a0, a1, a2, a3, asq, r;
register int dir, i;
register site *st;
su3_matrix action;
su2_matrix u;

Nhit = 3;

    for( NumTrj = 0 ; NumTrj < NumStp; NumTrj++)
    for( subl = 0; subl < N_SUBL32; subl++) {

	FORALLUPDIR(dir) {
	    /* updating links in direction dir */
	    /* compute the staple */
	    dsdu_qhb_subl(dir, subl);

	    for(index1=0;index1< Nhit;index1++) {
		/*  pick out an SU(2) subgroup */
		ina=(index1+1) % Nc;
		inb=(index1+2) % Nc;
		if(ina > inb){ ii=ina; ina=inb; inb=ii;}

		FORSOMESUBLATTICE(i,st,subl) {
		    mult_su3_na(&(st->link[dir]), &(st->staple), &action);

/*decompose the action into SU(2) subgroups using Pauli matrix expansion */
/* The SU(2) hit matrix is represented as a0 + i * Sum j (sigma j * aj)*/
		    a0 =  action.e[ina][ina].real + action.e[inb][inb].real;
		    a3 =  action.e[ina][ina].imag - action.e[inb][inb].imag;
		    a1 =  action.e[ina][inb].imag + action.e[inb][ina].imag;
		    a2 =  action.e[ina][inb].real - action.e[inb][ina].real;

		    /* Normalize and complex conjugate u */

		    asq = a0*a0 + a1*a1 + a2*a2 + a3*a3;
		    r = sqrt((double)asq );
		    a0 = a0/r; a1 = -a1/r; a2 = -a2/r; a3 = -a3/r;

		    /* Elements of SU(2) matrix */
		    u.e[0][0] = cmplx( a0, a3);
		    u.e[0][1] = cmplx( a2, a1);
		    u.e[1][0] = cmplx(-a2, a1);
		    u.e[1][1] = cmplx( a0,-a3);

		    /* Do SU(2) hit on all links twice (to overrelax)  */
		    left_su2_hit_n(&u,ina,inb,&(st->link[dir]));
		    left_su2_hit_n(&u,ina,inb,&(st->link[dir]));

		} /*  st */
	    } /*   hits */
	} /*  direction */
    } /*  subl, NumTrj */
コード例 #5
0
void CIIRfilter::lp_to_br(complex *p, char *ptype, int np, double fl, double fh, double *sn, double *sd, int *ns )
{
	complex	pinv, ctemp, p1, p2;
	double	pi, twopi, a, b;
	int	i, iptr;
        pi = M_PI;
        twopi = 2.*pi;
        a = twopi*twopi*fl*fh;
        b = twopi*( fh - fl );
        *ns = 0;
        iptr = 0;
	for (i = 0; i < np; i++)
	{
		if (    ptype[i] == 'C' )
		{
			pinv = cmplx_div(cmplx(1.,0.), p[i]);
			ctemp = cmplx_mul(real_cmplx_mul(b,pinv), 
				real_cmplx_mul(b, pinv));
			ctemp = cmplx_sub(ctemp, cmplx(4.*a, 0.));
			ctemp = cmplx_sqrt( ctemp );
			p1 = real_cmplx_mul(0.5, 
				cmplx_add(real_cmplx_mul(b,pinv), ctemp));
			p2 = real_cmplx_mul(0.5, 
				cmplx_sub(real_cmplx_mul(b,pinv), ctemp));
			sn[ iptr ]     = a;
			sn[ iptr + 1 ] = 0.;
			sn[ iptr + 2 ] = 1.;
			sd[iptr] = real_part(cmplx_mul(p1, cmplx_conjg(p1)));
			sd[ iptr + 1 ] = -2. * real_part(p1);
			sd[ iptr + 2 ] = 1.;
			iptr = iptr + 3;
			sn[ iptr ]     = a;
			sn[ iptr + 1 ] = 0.;
			sn[ iptr + 2 ] = 1.;
			sd[iptr] = real_part(cmplx_mul(p2, cmplx_conjg(p2)));
			sd[ iptr + 1 ] = -2. * real_part(p2);
			sd[ iptr + 2 ] = 1.;
			iptr = iptr + 3;
			*ns = *ns + 2;
		}
		else if (  ptype[i] == 'S' )
		{
			sn[ iptr ]     = a;
			sn[ iptr + 1 ] = 0.;
			sn[ iptr + 2 ] = 1.;
			sd[ iptr ]     = -a*real_part( p[i] );
			sd[ iptr + 1 ] = b;
			sd[ iptr + 2 ] = -real_part( p[i] );
			iptr = iptr + 3;
			*ns = *ns + 1;
		}
	}
}
コード例 #6
0
ファイル: suacorfrac.c プロジェクト: gwowen/seismicunix
/************************************************************************
dopow - raise a complex number to seperate real powers for amp and phase
*************************************************************************
Notes:

Aout exp[-i Pout] = Ain^a exp[-i b Pin] 
     where A=amplitude  P=phase
*************************************************************************
UHouston: Chris Liner: modified from D. Hale subroutine crpow
*************************************************************************/
complex dopow(complex u, float a, float b)
{
	float ur,ui,amp,phs;

	if (a==0.0) return cmplx(1.0,0.0);
	if (u.r==0.0 && u.i==0.0) return cmplx(0.0,0.0);

	ur = u.r; 
	ui = u.i;
	amp = exp(0.5*a*log(ur*ur+ui*ui));
	phs = -b*atan2(ui,ur);

	return cmplx(amp*cos(phs),amp*sin(phs));	
}
コード例 #7
0
ファイル: frame.c プロジェクト: hd1812/RTDSP-Projects
/******************* Wait for buffer of data to be input/output **********************/
void wait_buffer(void)
{
	float *p;  
	int i;
	/* wait for array index to be set to zero by ISR */
	while(index);
	
	/* rotate data arrays */
	p = input;
	input = output;
	output = intermediate;
	intermediate = p;
	
	/************************* DO PROCESSING OF FRAME  HERE **************************/                
	for(i=0;i<BUFLEN;i++){
		buffer[i]=cmplx(intermediate[i],0);
	}
	
	fft(BUFLEN,buffer);
	
	for(i=0;i<BUFLEN;i++){
		mag[i]=cabs(buffer[i]);
	}
	
	/**********************************************************************************/
	
	/* wait here in case next sample has not yet been read in */                          
	while(!index);
}        
コード例 #8
0
ファイル: Correlators.cpp プロジェクト: chelmes/Contraction
void LapH::Correlators::compute_correlators(const size_t config_i){

  // initialising the big arrays
  set_corr(config_i);
  // setting the correlation functions to zero
//  std::fill(Corr.data(), Corr.data()+Corr.num_elements(), cmplx(.0,.0));
  std::fill(C4_mes.data(), C4_mes.data()+C4_mes.num_elements(), cmplx(.0,.0));

  // global variables from input file needed here
  const int Lt = global_data->get_Lt();

  // memory for intermediate matrices when building C4_3 (save multiplications)
  LapH::CrossOperator X(2);

  basic.init_operator('b', vdaggerv, peram);

  // computing the meson correlator which can be used to compute all small
  // trace combinations for 2pt and 4pt functions
  build_Corr();

  // computing the meson 4pt big cross trace
  // TODO: if condition that at least four random vectos are needed
  compute_meson_4pt_cross_trace(X);
//
  write_C4_3(config_i);
  build_and_write_2pt(config_i);
  build_and_write_C4_1(config_i);
  build_and_write_C4_2(config_i);

}
コード例 #9
0
ファイル: grsource_w.c プロジェクト: erinaldi/milc_qcd
void grsource_w() {
register int i,j,k;
register site *s;
    FORMYSITES(i,s){
        for(k=0;k<4;k++)for(j=0;j<3;j++){
#ifdef SITERAND
            s->g_rand.d[k].c[j].real = gaussian_rand_no(&(s->site_prn));
            s->g_rand.d[k].c[j].imag = gaussian_rand_no(&(s->site_prn));
#else
            s->g_rand.d[k].c[j].real = gaussian_rand_no(&node_prn);
            s->g_rand.d[k].c[j].imag = gaussian_rand_no(&node_prn);
#endif
	    s->psi.d[k].c[j] = cmplx(0.0,0.0);
        }
    }

#ifdef LU
    /* use g_rand on odd sites as temporary storage:
        g_rand(odd) = Dslash^adjoint * g_rand(even) */
    dslash_w_site( F_OFFSET(g_rand), F_OFFSET(g_rand), MINUS, ODD);
    dslash_w_site( F_OFFSET(g_rand), F_OFFSET(chi)   , MINUS, EVEN);
    FOREVENSITES(i,s){
        scalar_mult_add_wvec( &(s->g_rand), &(s->chi), -kappa*kappa,
            &(s->chi) );
    }
コード例 #10
0
//Processing when import frame
void frame_in(){
	int k;
	float mag;
	for(k=0;k<FFTLEN;k++){
		buffer[k]=cmplx(inframe[k],0);	
	}	 
	//perform FFT
	fft(FFTLEN,buffer);
	//rotate every 2.5s
	if(i== 312){
	M4=M3;
	M3=M2;
	M2=M1;	
	M1=M4;						      		
	i=0;
	}
	//Import to M1
	if(i==0){
		for(k=0;k<FFTLEN;k++){
			M1[k]=cabs(buffer[k]);			
		}	
	}
	else{
		for(k=0;k<FFTLEN;k++){
			mag=cabs(buffer[k]);
			M1[k]=(1-lpf_weight_speech)*mag+lpf_weight_speech*M1[k];
		}
	}
}
コード例 #11
0
ファイル: pfamcct.c プロジェクト: JOravetz/SeisUnix
main()
{
	int n1,n2,j;
	float scale,sumz,sume;
 
	for (n1=1,n2=npfa(n1+1); n2<NMAX; n1=n2,n2=npfa(n1+1)) {
		for (j=0; j<n1*n2; j++)
			c[j] = z[j] = cmplx(franuni(),franuni());
		pfamcc(1,n1,n2,1,n1,z);
		pfamcc(1,n2,n1,n1,1,z);
		pfamcc(-1,n1,n2,1,n1,z);
		pfamcc(-1,n2,n1,n1,1,z);
		scale = 1.0/(float)(n1*n2);
		for (j=0; j<n1*n2; j++)
			z[j] = crmul(z[j],scale);

		for (j=0,sumz=sume=0.0; j<n1*n2; j++) {
			sumz += fcabs(z[j]);
			sume += fcabs(csub(z[j],c[j]));
		}
		printf("n1 = %d  n2 = %d  sume/sumz = %0.10f\n",
			n1,n2,sume/sumz);
		if (sume/sumz>1.0e-6) printf("!!! warning !!!\n");
	}
}
コード例 #12
0
ファイル: pfa2b.c プロジェクト: JOravetz/SeisUnix
main()
{
	int n,nc,nr,i;
	float *rz=(float*)cz;
	float cpucc,cpurc;

	for (nc=npfa(NMIN),nr=npfar(nc);
		nc<NMAX && nr<NMAX;
		nc=npfa(nc+1),nr=npfar(nc)) {

		for (i=0; i<nc*nc; i++)
			cz[i] = cmplx(0.0,0.0);
		cpucc = cpusec();
		pfa2cc(1,1,nc,nc,cz);
		cpucc = cpusec()-cpucc;

		for (i=0; i<nr*nr; i++)
			rz[i] = 0.0;
		cpurc = cpusec();
		pfa2rc(1,1,nr,nr,rz,cz);
		cpurc = cpusec()-cpurc;

		printf("nc,nr,cc,rc,cc/rc = %d %d %f %f %f\n",
			nc,nr,cpucc,cpurc,cpucc/cpurc);
	}
}
コード例 #13
0
ファイル: Correlators.cpp プロジェクト: knippsch/cntr.v0.1
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::Correlators::build_C1(const Quarklines& quarklines,
                    const std::vector<CorrInfo>& corr_lookup,
                    const QuarklineLookup& quark_lookup,
                    const std::vector<RandomIndexCombinationsQ2>& ric_lookup) {

  std::cout << "\tcomputing C1:";
  clock_t time = clock();

  for(const auto& c_look : corr_lookup){
    const auto& ric = ric_lookup[quark_lookup.Q1[c_look.lookup[0]].
                                                     id_ric_lookup].rnd_vec_ids;
    std::vector<cmplx> correlator(Lt*ric.size(), cmplx(.0,.0));
    for(size_t t = 0; t < Lt; t++){
      for(const auto& id : ric){
        correlator[(&id-&ric[0])*Lt + t] +=
         quarklines.return_Q1(t, t/dilT, c_look.lookup[0], &id-&ric[0]).trace();
      }
    }
    // write data to file
    write_correlators(correlator, c_look);
  }
  time = clock() - time;
  std::cout << "\t\t\tSUCCESS - " << ((float) time) / CLOCKS_PER_SEC 
            << " seconds" << std::endl;
}
コード例 #14
0
ファイル: Correlators.cpp プロジェクト: knippsch/cntr.v0.1
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::Correlators::build_C2c(const std::vector<CorrInfo>& corr_lookup) {

  for(const auto& c_look : corr_lookup){
    std::vector<cmplx> correlator(Lt, cmplx(.0,.0));
    if(c_look.outfile.find("Check") == 0){
      for(int t1 = 0; t1 < Lt; t1++){
        for(const auto& corr : corrC[c_look.lookup[0]][t1][t1]){
          correlator[t1] += corr;
        }
      }
      // normalisation
      for(auto& corr : correlator)
        corr /= corrC[c_look.lookup[0]][0][0].size();
      // write data to file
      write_correlators(correlator, c_look);
    }
    else{
      for(int t1 = 0; t1 < Lt; t1++){
      for(int t2 = 0; t2 < Lt; t2++){
        int t = abs((t2 - t1 - (int)Lt) % (int)Lt);
        for(const auto& corr : corrC[c_look.lookup[0]][t1][t2]){
          correlator[t] += corr;
        }
      }}
      // normalisation
      for(auto& corr : correlator)
        corr /= Lt*corrC[c_look.lookup[0]][0][0].size();
      // write data to file
      write_correlators(correlator, c_look);
    }
  }
}
コード例 #15
0
void rectangle::divide(rectangle & r1, rectangle & r2, double ratio){
    auto width = (z2 - z1).real();
    auto height = (z2 - z1).imag();

    // вот этот кусок стоит упростить
    if (width > height) {
        auto u1 = z1, u2 = z2 - (z2 - z1).real() / (1. + ratio);
        r1 = {u1, u2};

        u1 = z1 + (z2 - z1).real() * ratio / (1. + ratio), u2 = z2;
        r2 = {u1, u2};
    } else {
        auto u1 = z1, u2 = z2 - cmplx(0, (z2 - z1).imag() / (1. + ratio));
        r1 = {u1, u2};

        u1 = z1 + cmplx(0, (z2 - z1).imag() * ratio / (1. + ratio)), u2 = z2;
        r2 = {u1, u2};
    }
}
コード例 #16
0
void wl_2l_2corr_offax(int tot_smear, int step) {

    register int i,dir1,dir2,dir3,r,t,r_off;
    int nth,nxh,nrmax,j,k,num_lp,rmax;
    register site *s;
    dble_su3_vec_src *dpt;
    su3_vector tvec1,tvec2;
    msg_tag *mtag[8],*gmtag;
    complex  cc,cc1,cc2;
    complex *wl2_mes, *wl2_mes_d;
    Real ftmpr, ftmpi, fns, xnsrc;
    field_offset meson1, meson2, meson_f, mes_t;
    int disp[4];    /* displacement vector for general gather */


    meson1 = F_OFFSET(xxx.c[0]);
    meson2 = F_OFFSET(xxx.c[1]);
    meson_f = F_OFFSET(ttt.c[0]);
    mes_t = F_OFFSET(ttt.c[1]);

    if( nx != ny || nx != nz) {
        if(this_node == 0)printf("wl_2lprop gives wrong results for nx!=ny!=nz");
        return;
    }

    xnsrc = num_src*(num_src-1);
    nth = nt/2;
    nxh = nx/2;
    nrmax = 4;
    wl2_mes = (complex *)malloc(nth*nrmax*sizeof(complex));
    wl2_mes_d = (complex *)malloc(nth*nrmax*sizeof(complex));

    for(t=0; t<nth; t++) for(r=0; r<nrmax; r++) {
            wl2_mes[r+nrmax*t] = cmplx(0.0,0.0);
            wl2_mes_d[r+nrmax*t] = cmplx(0.0,0.0);
        }


    FORALLSITES(i,s) {
        su3_vec_to_src( &(s->qprop[0]), &(s->dtmpvecs[0].n[0]), num_src);
        su3_vec_to_src( &(s->g_rand[0]), &(s->dtmpvecs[0].n[1]), num_src);
    }
コード例 #17
0
ファイル: rand_gauge.c プロジェクト: andypea/MILC
void randomize(field_offset G, Real radius)
{
  register int a, b, i;
  site *s;

  FORALLSITES(i,s) {
    for(a=0; a<3; a++) for(b=0; b<3; b++)
      (*(su3_matrix *)F_PT(s,G)).e[a][b] 
             = cmplx(radius*((Real)drand48()-0.5),
                     radius*((Real)drand48()-0.5));
    reunit_su3((su3_matrix *)F_PT(s,G));
  }
}
コード例 #18
0
ファイル: stout_smear_utilities.c プロジェクト: andypea/MILC
static void 
get_Q_from_VUadj(su3_matrix *Q, su3_matrix *V, su3_matrix *U){

  complex minusI;
  complex tr;
  su3_matrix Omega;

  minusI = cmplx(0, -1);  /* -i */

  /* Omega = V U^adj */
  mult_su3_na( V, U, &Omega );

  /* Q = traceless hermitian part of [-i Omega] */
  c_scalar_mult_su3mat( &Omega, &minusI, &Omega );
  traceless_hermitian_su3( Q, &Omega );
}
コード例 #19
0
ファイル: Correlators.cpp プロジェクト: knippsch/cntr.v0.1
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::Correlators::build_corr0(const Quarklines& quarklines,
                     const std::vector<CorrInfo>& corr_lookup,
                     const QuarklineLookup& quark_lookup,
                     const std::vector<RandomIndexCombinationsQ2>& ric_lookup) {

  std::cout << "\tcomputing corr0:";
  clock_t time = clock();

  corr0.resize(boost::extents[corr_lookup.size()][Lt][Lt]);
  for(const auto& c_look : corr_lookup){
    const auto& ric0 = ric_lookup[quark_lookup.Q1[c_look.lookup[0]].
                                                     id_ric_lookup].rnd_vec_ids;
    const auto& ric1 = ric_lookup[quark_lookup.Q1[c_look.lookup[1]].
                                                     id_ric_lookup].rnd_vec_ids;
    if(ric0.size() != ric1.size()){
      std::cout << "rnd combinations are not the same in build_corr0" 
                << std::endl;
      exit(0);
    }
    for(size_t t1 = 0; t1 < Lt; t1++){
    for(size_t t2 = 0; t2 < Lt; t2++){
      corr0[c_look.id][t1][t2].resize(ric0.size());
      for(auto& corr : corr0[c_look.id][t1][t2])
        corr = cmplx(0.0,0.0);
      for(const auto& rnd : ric0){
        const auto id = &rnd - &ric0[0];
        const auto it1 = std::find_if(ric1.begin(), ric1.end(),
                                [&](std::pair<size_t, size_t> pair){
                                  return (pair == 
                                         std::make_pair(rnd.second, rnd.first));
                                });
        if(it1 == ric1.end()){
          std::cout << "something wrong with random vectors in build_corr0" 
                    << std::endl;
          exit(0);
        }
        corr0[c_look.id][t1][t2][id] += 
                    (quarklines.return_Q1(t1, t2/dilT, c_look.lookup[0], id) *
                     quarklines.return_Q1(t2, t1/dilT, c_look.lookup[1], 
                                                     it1-ric1.begin())).trace();
      }
    }}
  }
  time = clock() - time;
  std::cout << "\t\tSUCCESS - " << ((float) time) / CLOCKS_PER_SEC 
            << " seconds" << std::endl;
}
コード例 #20
0
ファイル: enhance.c プロジェクト: hd1812/RTDSP-Projects
//Processing when import frame
void frame_in(){
	int k,n;
	float mag;
	
	for(k=0;k<FFTLEN;k++){
		buffer[k]=cmplx(inframe[k],0);	
	}	 
	//perform FFT
	fft(FFTLEN,buffer);
	//rotate every 2.5s
	n=rotate_inteval*FSAMP*OVERSAMP/FFTLEN;
	if(i== n){
	M4=M3;
	M3=M2;
	M2=M1;	
	M1=M4;						      		
	i=0;
	}
	//Import to M1
	if(i==0){
		for(k=0;k<FFTLEN;k++){
			M1[k]=cabs(buffer[k]);			
		}	
	}
	else{
		if(lpf_switch==0){
			for(k=0;k<FFTLEN;k++){
				mag=cabs(buffer[k]);
				if(M1[k]>mag){
					M1[k]=mag;
				}
			}
		}
		else{
			for(k=0;k<FFTLEN;k++){
				if(lpf_power_switch==1){
				mag=cabs(cmul(buffer[k],buffer[k]));
				M1[k]=sqrt((1-lpf_weight)*mag+lpf_weight*(M1[k]*M1[k]));
				}
				else{
				mag=cabs(buffer[k]);
				M1[k]=(1-lpf_weight)*mag+lpf_weight*M1[k];
				}
			}
		}	 
	}
}
コード例 #21
0
ファイル: pfab.c プロジェクト: JOravetz/SeisUnix
main()
{
	int n=NMIN,nfft,i,it;
	float cpucc;

	for (i=0; i<NMAX; i++)
		z[i] = cmplx(0.0,0.0);

	for (n=NMIN; n<=NMAX; n+=NSTEP) {
		nfft = npfa(n);
		cpucc = cpusec();
		for (it=0; it<NT; it++)
			pfacc(1,nfft,z);
		cpucc = cpusec()-cpucc;
		cpucc /= NT;
		printf("n = %d  nfft = %d  sec = %f\n",n,nfft,cpucc);
	}
}
コード例 #22
0
ファイル: Correlators.cpp プロジェクト: knippsch/cntr.v0.1
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::Correlators::build_corrC(const Quarklines& quarklines, 
                     const OperatorsForMesons& meson_operator,
                     const OperatorLookup& operator_lookup,
                     const std::vector<CorrInfo>& corr_lookup,
                     const QuarklineLookup& quark_lookup) {

  std::cout << "\tcomputing corrC:";
  clock_t time = clock();

  corrC.resize(boost::extents[corr_lookup.size()][Lt][Lt]);
  for(const auto& c_look : corr_lookup){
    const auto& ric0 = operator_lookup.ricQ2_lookup[
                  quark_lookup.Q2V[c_look.lookup[0]].id_ric_lookup].rnd_vec_ids;
    const auto& ric1 = operator_lookup.ricQ2_lookup[//needed only for checking
               operator_lookup.rvdaggervr_lookuptable[c_look.lookup[1]].
                                                    id_ricQ_lookup].rnd_vec_ids;
    if(ric0.size() != ric1.size()){
      std::cout << "rnd combinations are not the same in build_corrC" 
                << std::endl;
      exit(0);
    }
    for(size_t t1 = 0; t1 < Lt; t1++){
    for(size_t t2 = 0; t2 < Lt; t2++){
      corrC[c_look.id][t1][t2].resize(ric0.size());
      for(auto& corr : corrC[c_look.id][t1][t2])
        corr = cmplx(0.0,0.0);
      for(const auto& rnd : ric0){
        const auto id = &rnd - &ric0[0];
        for(size_t block = 0; block < 4; block++){
          const auto gamma_index = quarklines.return_gamma_row(c_look.gamma[0], block);
          corrC[c_look.id][t1][t2][id] += 
               quarklines.return_gamma_val(c_look.gamma[0], block) *
               (quarklines.return_Q2V(t1, t2/dilT, c_look.lookup[0], id).
                                  block(block*dilE, gamma_index*dilE, dilE, dilE) *
               meson_operator.return_rvdaggervr(c_look.lookup[1], t2, id).block(
                            gamma_index*dilE, block*dilE, dilE, dilE)).trace();
        }
      }
    }}
  }
  time = clock() - time;
  std::cout << "\t\tSUCCESS - " << ((float) time) / CLOCKS_PER_SEC 
            << " seconds" << std::endl;
}
コード例 #23
0
ファイル: Correlators.cpp プロジェクト: chelmes/Contraction
LapH::Correlators::Correlators() : basic(), peram(), rnd_vec(), vdaggerv(),
                                   C4_mes(), C2_mes(), Corr()  {

  const vec_index_2pt op_C2 = global_data->get_lookup_2pt_trace();
  const size_t nb_op_2pt = op_C2.size();
  const vec_index_4pt op_C4 = global_data->get_lookup_4pt_trace();
  const size_t nb_op_4pt = op_C4.size();
  const vec_pdg_Corr op_Corr = global_data->get_lookup_corr();
  const size_t nb_op = op_Corr.size();
//  const size_t nb_op = global_data->get_number_of_operators();
  const std::vector<quark> quarks = global_data->get_quarks();

  const size_t Lt = global_data->get_Lt();
  const size_t nb_ev = global_data->get_number_of_eigen_vec();

  const size_t nb_rnd = quarks[0].number_of_rnd_vec +2;

  rnd_vec.resize(quarks.size());
  for(const auto& q: quarks){
    rnd_vec[q.id].resize(q.number_of_rnd_vec);
    for(size_t rnd = 0; rnd < q.number_of_rnd_vec; rnd++)
      rnd_vec[q.id][rnd] = LapH::RandomVector(Lt*nb_ev*4);
  }

  //TODO: size of C4_mes and C2_mes must be replaced by size of corresponding
  //operator lists. Momentary values are upper limit
  C4_mes.resize(boost::extents[nb_op_4pt][Lt]);
  C2_mes.resize(boost::extents[nb_op_2pt][Lt]);

  Corr.resize(boost::extents[nb_op][nb_op][Lt][Lt]);
  for(size_t op1 = 0; op1 < nb_op; op1++)
  for(size_t op2 = 0; op2 < nb_op; op2++)
  for(size_t t1 = 0; t1 < Lt; t1++)
  for(size_t t2 = 0; t2 < Lt; t2++){
    Corr[op1][op2][t1][t2].resize(nb_rnd);
    for(size_t rnd1 = 0; rnd1 < nb_rnd; rnd1++){
      Corr[op1][op2][t1][t2][rnd1].resize(nb_rnd);
      for(size_t rnd2 = 0; rnd2 < nb_rnd; rnd2++)
        Corr[op1][op2][t1][t2][rnd1][rnd2] = cmplx(0.0,0.0);
    }
  }
    
}
コード例 #24
0
ファイル: blocked_plaq.c プロジェクト: daschaich/susy
void blocked_plaq(int Nsmear, int block) {
  register int i;
  register site *s;
  int j, stride = 1;
  double plaq = 0.0, plaqSq = 0.0, re = 0.0, reSq = 0.0, im = 0.0, imSq = 0.0;
  double sum = 0.0, norm = 1.0 / volume, tr;
  complex det = cmplx(0.0, 0.0), tc;
  matrix tmat, tmat2, tmat3;

  // Set number of links to stride, 2^block
  for (j = 0; j < block; j++)
    stride *= 2;

  // Compute the strided plaquette, exploiting a symmetry under TUP<-->XUP
  // Copy links to tempmat and tempmat2 to be shifted
  FORALLSITES(i, s) {
    mat_copy(&(s->link[TUP]), &(tempmat[i]));
    mat_copy(&(s->link[XUP]), &(tempmat2[i]));
  }
コード例 #25
0
ファイル: stout_smear.c プロジェクト: erinaldi/milc_qcd
static void 
get_Q_from_VUadj(su3_matrix *Q, su3_matrix *V, su3_matrix *U){

  complex x;
  complex tr;
  su3_matrix Om;

  x = cmplx(0, 0.5);  /* i/2 */

  /* Om = V U^adj */
  mult_su3_na( V, U, &Om );

  /* Q = i/2(Om^adj - Om) */
  su3_adjoint( &Om, Q );
  sub_su3_matrix( Q, &Om, &Om );
  c_scalar_mult_su3mat( &Om, &x, Q );
  /* Q = Q - Tr Q/3 */
  tr = trace_su3( Q );
  CDIVREAL(tr, 3., tr);
  CSUB(Q->e[0][0],tr,Q->e[0][0]);
  CSUB(Q->e[1][1],tr,Q->e[1][1]);
  CSUB(Q->e[2][2],tr,Q->e[2][2]);
}
コード例 #26
0
ファイル: Correlators.cpp プロジェクト: knippsch/cntr.v0.1
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::Correlators::build_C4cV(const OperatorLookup& operator_lookup, 
                                   const CorrelatorLookup& corr_lookup,
                                   const QuarklineLookup& quark_lookup) {

  for(const auto& c_look : corr_lookup.C4cV){
    std::vector<cmplx> correlator(Lt, cmplx(.0,.0));
    const size_t id0 = corr_lookup.corrC[c_look.lookup[0]].lookup[0];
    const size_t id1 = corr_lookup.corrC[c_look.lookup[1]].lookup[0];
    const auto& ric0 = operator_lookup.ricQ2_lookup[quark_lookup.Q2V[id0].
                                                     id_ric_lookup].rnd_vec_ids;
    const auto& ric1 = operator_lookup.ricQ2_lookup[quark_lookup.Q2V[id1].
                                                     id_ric_lookup].rnd_vec_ids;

    size_t norm = 0;
    for(int t1 = 0; t1 < Lt; t1++){
    for(int t2 = 0; t2 < Lt; t2++){
      int t = abs((t2 - t1 - (int)Lt) % (int)Lt);

      for(const auto& rnd0 : ric0)
      for(const auto& rnd1 : ric1)

      if((rnd0.first != rnd1.first) && (rnd0.first != rnd1.second) &&
         (rnd0.second != rnd1.first) && (rnd0.second != rnd1.second)){

        correlator[t] += 
                   corrC[c_look.lookup[0]][t1][t1].at(&rnd0 - &ric0[0]) *
                   corrC[c_look.lookup[1]][t2][t2].at(&rnd1 - &ric1[0]);
        norm++;
      }
    }}
    // normalisation
    for(auto& corr : correlator)
      corr /= norm/Lt;
    // write data to file
    write_correlators(correlator, c_look);
  }
}
コード例 #27
0
ファイル: RandomVector.cpp プロジェクト: chelmes/Contraction
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LapH::RandomVector::set(const int seed) {

  // initialisation of the rando vector to create Z2 random vector
  size_t length = vec.size();
  rlxs_init(0, seed);
  std::vector<float> rnd(2*length);
  ranlxs(&(rnd[0]), 2*length);

  // generating a Z_2 source
  for(size_t i = 0; i < length; ++i){
    const double sqrt2 = 0.5*sqrt(2.0);
    double re, im;
    if (rnd[2*i] < 0.5)
      re = -sqrt2;
    else
      re = sqrt2;
    if (rnd[2*i + 1] < 0.5)
      im = -sqrt2;
    else
      im = sqrt2;
    vec[i] = cmplx(re, im);
  }

}
コード例 #28
0
void monte_block_ape_b(int NumStp1)
{
int NumTrj,Nhit, index1, ina, inb,ii,cb;
int parity;
Real b3;
register int dir,i;
register site *st;
void dsdu_ape(register int dir1, int parity);
su3_matrix tmat1;
Real a0,a1,a2,a3,asq;
int index,ind1,ind2,step;
su2_matrix h;
Real alpha;

int NumStp;
NumStp=3 ;

Nhit=5;

alpha=0.3;
b3=alpha/(1.0-alpha)/6.0;
b3=1.0/b3;

if(this_node==0)printf("pure APE blocking with alpha  %e N %d\n",alpha,NumStp);

/*  set bb_link=link */
 
                FORALLSITES(i,st)for(dir=XUP;dir<=TUP;dir++){
                st->blocked_link[8+dir]= st->link[dir];
               }
/* ape blocking steps_rg levels*/
 
        for(step=1;step<=NumStp;step++){


        for(parity=ODD;parity<=EVEN;parity++)
	for(dir=XUP;dir<=TUP;dir++){

              /* compute the gauge force */
		dsdu_ape(dir,parity); 

        FORSOMEPARITY(i,st,parity){
	{
/* set blocked_link=bb_link temporarily*/
                 st->blocked_link[4+dir]= st->blocked_link[8+dir];
/* add the staple to the blocked link. ``staple'' will become the new
blocked_link after normalization */
                scalar_mult_add_su3_matrix(&(st->tempmat2),
	 &(st->blocked_link[8+dir]),b3,&(st->tempmat2));
  
/* if(i==0&&step==1){
	printf("\n\n step=%d i=%d dir=%d\n",step,i,dir);
	dumpmat(&(st->blocked_link[8+dir]));
	dumpmat(&(st->tempmat2));
}*/

        /* Now do hits in the SU(2) subgroup to "normalize" staple */

        for(index=0;index<3*Nhit;index++){

             /*  pick out an SU(2) subgroup */
                        ind1=(index) % 3;
                        ind2=(index+1) % 3;

                        if(ind1 > ind2){ ii=ind1; ind1=ind2; ind2=ii;}



                mult_su3_na( &(st->blocked_link[4+dir]), &(st->tempmat2), &tmat1 );

                /* Extract SU(2) subgroup in Pauli matrix representation,
                   a0 + i * sum_j a_j sigma_j, from the SU(3) matrix tmat1 */
                a0 = tmat1.e[ind1][ind1].real + tmat1.e[ind2][ind2].real;
                a1 = tmat1.e[ind1][ind2].imag + tmat1.e[ind2][ind1].imag;
                a2 = tmat1.e[ind1][ind2].real - tmat1.e[ind2][ind1].real;
                a3 = tmat1.e[ind1][ind1].imag - tmat1.e[ind2][ind2].imag;

                /* Normalize and put complex conjugate into u */
                asq = a0*a0 + a1*a1 + a2*a2 + a3*a3;
                asq = sqrt((double)asq);
                a0 = a0/asq; a1 = a1/asq; a2 = a2/asq; a3 = a3/asq;
                h.e[0][0] = cmplx( a0,-a3);
                h.e[0][1] = cmplx(-a2,-a1);
                h.e[1][0] = cmplx( a2,-a1);
                h.e[1][1] = cmplx( a0, a3);

                /* Do the SU(2) hit */
                left_su2_hit_n( &h, ind1, ind2, &(st->blocked_link[4+dir]));
		} /* indices */
            } /* end loop over sites */

	}} /*  direction and parity */
コード例 #29
0
void meson_cont_mom(complex prop[],
		    field_offset src1,field_offset src2,
		    int base_pt, int q_stride, int op_stride,
		    gamma_corr gamma_table[], int no_gamma_corr)
{
  register int i;
  register site *s; 
  
  double theta ; 
  double factx = 2.0*PI/(1.0*nx) ; 
  double facty = 2.0*PI/(1.0*ny) ; 
  double factz = 2.0*PI/(1.0*nz) ; 
  Real px,py,pz;
  complex phase_fact ; 
  
  int my_t;
  int cf, sf, si;
  int i_gamma_corr,q_pt,prop_pt;
  
  complex g1,g2;
  
  spin_wilson_vector localmat,localmat2;  /* temporary storage */
  spin_wilson_vector quark;               /* temporary storage for quark */
  spin_wilson_vector antiquark;           /* temporary storage for antiquark */
  
  
  FORALLSITES(i,s)
    {
      
      my_t = s->t;
      
      /* copy src2 into quark */
      for(si=0;si<4;si++)
	for(sf=0;sf<4;sf++)
	  for(cf=0;cf<3;cf++)
	    {
	      quark.d[si].d[sf].c[cf] = 
		((spin_wilson_vector *)F_PT(s,src2))->d[si].d[sf].c[cf];
	    }
      
      /* next, construct antiquark from src1 */
      /*first, dirac multiplication by the source gamma matrices (on left) */
      
      /*  antiquark = c.c. of quark propagator */
      for(si=0;si<4;si++)
	for(sf=0;sf<4;sf++)
	  for(cf=0;cf<3;cf++)
	    {
	      
	      CONJG(((spin_wilson_vector *)F_PT(s,src1))->d[si].d[sf].c[cf],
		    antiquark.d[sf].d[si].c[cf]); 
	      
	    }
      
      
      /* left multiply antiquark by source gamma matrices,
	 beginning with gamma_5 for quark -> antiquark */
      mult_sw_by_gamma_l( &antiquark, &localmat, G5);    
      
      /* right dirac multiplication by gamma-5 (finishing up antiquark) */
      mult_sw_by_gamma_r( &localmat, &antiquark, G5);     
      
      /* Run through the table of source-sink gamma matrices */
      for(i_gamma_corr=0; i_gamma_corr<no_gamma_corr; i_gamma_corr++)
	{
	  /* left multiply by the particular source dirac matrices */
	  /* result in localmat2 */
	  
	  mult_sw_by_gamma_l( &antiquark, &localmat, 
			     gamma_table[i_gamma_corr].gin);
	  
	  mult_sw_by_gamma_r( &localmat, &localmat2,
			     gamma_table[i_gamma_corr].gout);
	  
	  /* Run through all sink momenta */
	  for(q_pt=0; q_pt<no_q_values; q_pt++)
	    {
	      px = q_momstore[q_pt][0];
	      py = q_momstore[q_pt][1];
	      pz = q_momstore[q_pt][2];
	      
	      theta = factx*(s->x)*px + facty*(s->y)*py + factz*(s->z)*pz; 
	      phase_fact = cmplx((Real) cos(theta)  , (Real) sin(theta)) ; 
	      
	      prop_pt = my_t + base_pt + q_pt * q_stride + i_gamma_corr * op_stride;
	      
	      /* trace over propagators */
	      for(si=0;si<4;si++)
		for(sf=0;sf<4;sf++)
		  for(cf=0;cf<3;cf++)
		    {
		      g1 = localmat2.d[si].d[sf].c[cf];
		      CMUL( quark.d[sf].d[si].c[cf] , phase_fact,  g2);    
		      
		      prop[prop_pt ].real += 
			(g1.real*g2.real - g1.imag*g2.imag); 
		      prop[prop_pt ].imag += 
			(g1.real*g2.imag + g1.imag*g2.real); 
		    }
	    }
	}
    }  /**** end of the loop over lattice sites ******/
コード例 #30
0
ファイル: supspimig.c プロジェクト: kechen89/PSPI-migration
/************************PSPI migration************************/
void pspimig(float **data,complex **image,float **v,int nt,int nx,int nz,float dt,float dx, float dz)
{
int ntfft;                              /*number of samples of the zero padded trace*/
int nxfft;
int nw;                                 /*number of temporal freqs.*/
int it;                                 /*loop index over time sample*/
int ix;                                 /*loop index over midpoint sample*/     
int iw;                                 /*loop index over frequency*/                 
int ik;                                 /*loop index over wavenumber*/
int iz;                                /*loop index over migrated depth samples*/
int iv;                                /*loop index over reference velocities*/
int nvref_max=8;                      /*number of reference velocities in each layer*/
int nvref;
int i1;                               /*nearest reference velocity*/
int i2;
int iw1;
int iw2;


float **vref;                           /*2D reference velocity array*/
float w0;                               /*first frequency sample*/
float w;                                /*frequency*/
float dw;                               /*frequency sampling interval*/                 
float k0;                               /*first wavenumber*/
float k;
float dk;                             /*wave number sampling interval in x*/
float dv;                              /*velocity interval*/
float *in;                             /*input 1D data in FFTW*/
float **cpdata;
float phase;
float wv;
float vmin;
float vmax;
float f1 = 1.0;
float f2 = 35.0;

complex *out;                           /*output of 1D FFT using FFTW*/
complex **datawx;                       /*data in frequency-wavenumber domain*/
complex *in2;
complex *out2;
complex *in3;
complex *out3;
complex **Pkv;                           /*wavefield in k-v*/
complex **Pxv;                           /*wavefield in x-v*/
complex **Pwx;                           /*wavefield in w-x*/

complex cshift;
complex tmp_a;
complex tmp_b;

fftwf_plan p1; 
fftwf_plan p2;
fftwf_plan p3;

/*allocate memory of reference velocities*/
vref = alloc2float(nz,nvref_max);     /*allocate 2D array for reference velocity to avoid changing memory of vector*/
                                      /*nz by nvref_max*/
for (ix=0;ix<nx;ix++){
for (iz=0;iz<nz;iz++){
image[ix][iz] = cmplx(0.0,0.0);       /*nz by nz*/
}
}


/*devide velocity by 2 for downward continuation*/
for (iz=0;iz<nz;iz++){
for (ix=0;ix<nx;ix++){
v[ix][iz]=v[ix][iz]/2.0;
}
}
 /*fprintf(stderr,"nx=%d nz=%d",nx,nz);
 FILE *Fvp = fopen("vel.bin", "wb");
 fwrite(v[0],1,4*nx*nz,Fvp);
 fclose(Fvp);*/


/*zero padding in termporal direction*/
ntfft = 1.0*exp2(ceil(log2(nt)));        /*number of zero padded trace in FFT*/
nw = ntfft/2+1;                          /*number of points of frequency axis after FFTW*/
cpdata = alloc2float(ntfft,nx);          /*data after zero padding*/  

for (ix=0;ix<nx;ix++){
 for (it=0;it<ntfft;it++){
   if(it<=nt) cpdata[ix][it] = data[ix][it];
   else {cpdata[ix][it] = 0.0;
         }
 		          }
	             }


/*allocate memory for w-x domain data*/
datawx = alloc2complex(nw,nx);           /*w-x data nx by nw*/
iw1 = floor(f1*dt*ntfft)+1;
iw2 = floor(f2*dt*ntfft)+1;

/*define plans for FFT using FFTW*/
/*plan 1 from t-x to w-x*/
in = alloc1float(ntfft);
out = alloc1complex(nw);
p1 = fftwf_plan_dft_r2c_1d(ntfft,in,(fftwf_complex*)out,FFTW_ESTIMATE);      /*real to complex*/

/*plan 2 from w-x to w-k*/
nxfft = 1.0*exp2(ceil(log2(nx)));
in2 =  alloc1complex(nxfft);
out2 = alloc1complex(nxfft);
p2 = fftwf_plan_dft_1d(nxfft,(fftwf_complex*)in2,(fftwf_complex*)out2,FFTW_FORWARD,FFTW_ESTIMATE);


/*plan 3 from w-k to w-x*/
in3 =  alloc1complex(nxfft);
out3 = alloc1complex(nxfft);
p3 = fftwf_plan_dft_1d(nxfft,(fftwf_complex*)in3,(fftwf_complex*)out3,FFTW_BACKWARD,FFTW_ESTIMATE);

Pxv = alloc2complex(nvref_max,nxfft);

Pkv = alloc2complex(nvref_max,nxfft);

Pwx = alloc2complex(nw,nxfft); 

/*apply first 1-D Fourier transform on data from t-x to w-x using FFTW package*/
for (ix=0;ix<nx;ix++){
for(it=0;it<ntfft;it++){
in[it] = cpdata[ix][it];                    /*assign one trace to a vector*/
}
fftwf_execute(p1);

for(iw=0;iw<nw;iw++){
datawx[ix][iw] = cdiv(out[iw], cmplx(sqrt(ntfft), 0.0));
}            /*w*/

}            /*x*/

fftwf_destroy_plan(p1);


/*determine frequency and wavenumber axis*/
dw = 2.0*PI/(ntfft*dt);                    /*frequency sampling interval*/
w0 = 0.0;                                  /*first frequency sample*/

dk = 2.0*PI/(nxfft*dx);                   /*wavenumber sampling interval*/
k0 = 0.0;                                 /*first wavenumber sample*/



/*initialization of downward wavefield*/
for (iw=0;iw<nw;iw++){
for (ix=0;ix<nxfft;ix++){
if (ix<nx){Pwx[ix][iw] =  datawx[ix][iw];}     
else{Pwx[ix][iw] = cmplx(0.0,0.0);}
}
}

/*loop over depth z*/
for (iz=0;iz<nz;iz++){                
fprintf(stderr,"depth sample %d\n",iz);

/*calculate reference velocities of each layer*/
vmin = v[0][iz];
vmax = v[0][iz]; 
for (ix=0;ix<nx;ix++){
if(v[ix][iz]>=vmax) vmax=v[ix][iz];       /*get the maximum velocity*/
if(v[ix][iz]<=vmin) vmin=v[ix][iz];       /*get the minimum velocity*/
}                  

dv = (vmax-vmin)/(nvref_max-1);

if(dv/vmax<=0.001){
nvref = 1;
vref[0][iz]=(vmin+vmax)/2;
}
else
{
nvref = nvref_max;
for (iv=0;iv<nvref_max;iv++)
{
vref[iv][iz] = vmin+dv*iv;
}
}


/*loop over frequencies*/
w = w0;
for (iw=iw1;iw<=iw2;iw++){
w = w0 + iw*dw;                               /*frequency axis (important)*/

/*apply phase-shift in w-x (optional)*/

/*datawx*/

/*Apply second FFT to tranform w-x data to w-k domain using FFTW*/
for (ix=0;ix<nxfft;ix++){
in2[ix] = Pwx[ix][iw];
}

fftwf_execute(p2);
for (ik=0;ik<nxfft;ik++){
out2[ik] = cdiv(out2[ik], cmplx(sqrt(nxfft), 0.0));
}

/*loop over wavenumbers*/
k = k0;
for (ik=0;ik<nxfft;ik++){

if (ik<=nxfft/2){
k = ik*dk;                           /*wavenumber axis (important)*/
}
else{
k = (ik-nxfft)*dk;
}
 
/*loop over reference velocities*/
for (iv=0;iv<nvref;iv++){
wv = w/vref[iv][iz];
if(wv>fabs(k)){                     /*note that k can be negative*/
phase = sqrt(wv*wv-k*k)*dz;
cshift = cmplx(cos(phase),sin(phase));
}
else{
cshift = cmplx(0.0,0.0);
}
Pkv[ik][iv] = cmul(out2[ik],cshift); 
}                               /*end for v*/

}                               /*end for k*/

   
/*from w-k go back to w-x domain*/
for (iv=0;iv<nvref;iv++){  /*inverse FFT for each velocity*/

for (ik=0;ik<nxfft;ik++){
in3[ik] = Pkv[ik][iv];
}    /*end for k*/

fftwf_execute(p3);


for (ix=0;ix<nxfft;ix++){
Pxv[ix][iv] = cdiv(out3[ix], cmplx(sqrt(nxfft), 0.0));
}    /*end for x*/

}    /*end for v*/     /*Pxv ix by iv*/


/*interpolation of wavefield in w-x*/
if (nvref==1){
for (ix=0;ix<nx;ix++){
Pwx[ix][iw] = Pxv[ix][0];
}
}
else
{
for (ix=0;ix<nx;ix++){ 
if (v[ix][iz]==vmax){i1=(v[ix][iz]-vmin)/dv-1;}
else
{i1 = (v[ix][iz]-vmin)/dv;}    /*find nearest reference velocity and wavefield*/
i2 = i1+1;
tmp_a = cadd(crmul(Pxv[ix][i1], vref[i2][iz]-v[ix][iz]) , crmul(Pxv[ix][i2], v[ix][iz]-vref[i1][iz]));
tmp_b = cmplx(vref[i2][iz]-vref[i1][iz], 0.0);
Pwx[ix][iw] = cdiv(tmp_a,tmp_b);
}          /*interpolate wavefield*/
}          /*end else*/

/*imaging condition*/
for (ix=0;ix<nx;ix++){
image[ix][iz] = cadd(image[ix][iz],Pwx[ix][iw]);
}

/*zero padding*/
for (ix=nx;ix<nxfft;ix++){
Pwx[ix][iw] = cmplx(0.0,0.0);
}

}       /*w*/
}       /*z*/

fftwf_destroy_plan(p2);
fftwf_destroy_plan(p3);

}   /*end pspimig migration function*/