示例#1
0
/********************************************//**
\brief Compute Inverse Fast Wavelet Transform (iFWT) on 1D array
\param array : input array (1D)
\param filter : name of the filter to use (from TransformationType enum)
\param origLength : original length of the array so the result is cut at this length
\param result : resulting transformed array
\param stop : flag indicating if we need to stop the process or not
\return boolean true if the execution is finished,
        false if the process has been stopped during the execution
***********************************************/
bool FWT::iFastWaveletTransf(const std::vector<float>& array,
                             const TransformationType filter,
                             const int origLength,
                             std::vector<float>& result,
                             bool* stop)
{
    // Get filters
    std::deque<float> h, g;
    compute_wavelet_filters(filter, h, g);
    
    // Reverse filters
    std::deque<float> hRev = h;
    std::reverse(hRev.begin(), hRev.end());
    std::deque<float> gRev = g;
    std::reverse(gRev.begin(), gRev.end());
    
    std::vector<float> inv(array.begin(), array.end());
    
    // iFWT
    int Jmax = log2((float)inv.size()) - 1;
    int Jmin = 0;
    for(int j = Jmin; j <= Jmax; ++j)
    {
        if(*stop)
        {
            return false;
        }
        std::vector<float> Coarse(&inv[0], &inv[pow(2., j)]);
        std::vector<float> Detail(&inv[pow(2., j)], &inv[pow(2.,j+1)]);
        
        // Get Coarse and Detail
        Coarse = cconv(upsampling(Coarse), hRev);
        Detail = cconv(upsampling(Detail), gRev);
        
        for(int k = 0; k < pow(2., j+1); ++k)
        {
            if(*stop)
            {
                return false;
            }
            inv[k] = Coarse[k] + Detail[k];
        }
        
    }
    
    // Remove points so result is origLength length
    int N = pow(2, ceil(log2((float)origLength))) - origLength;
    removePoints(inv, N);
    result = inv;
    return true;
}
示例#2
0
/*
 * T_WHILE T_LPARN expr T_RPARN
 */
void
while1(tnode_t *tn)
{

	if (!reached) {
		/* loop not entered at top */
		warning(207);
		reached = 1;
	}

	if (tn != NULL)
		tn = cconv(tn);
	if (tn != NULL)
		tn = promote(NOOP, 0, tn);
	if (tn != NULL && !issclt(tn->tn_type->t_tspec)) {
		/* controlling expressions must have scalar type */
		error(204);
		tn = NULL;
	}

	pushctrl(T_WHILE);
	cstk->c_loop = 1;
	if (tn != NULL && tn->tn_op == CON) {
		if (isityp(tn->tn_type->t_tspec)) {
			cstk->c_infinite = tn->tn_val->v_quad != 0;
		} else {
			cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
		}
	}

	expr(tn, 0, 1);
}
示例#3
0
/*
 * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN
 */
void
for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
{

	/*
	 * If there is no initialisation expression it is possible that
	 * it is intended not to enter the loop at top.
	 */
	if (tn1 != NULL && !reached) {
		/* loop not entered at top */
		warning(207);
		reached = 1;
	}

	pushctrl(T_FOR);
	cstk->c_loop = 1;

	/*
	 * Store the tree memory for the reinitialisation expression.
	 * Also remember this expression itself. We must check it at
	 * the end of the loop to get "used but not set" warnings correct.
	 */
	cstk->c_fexprm = tsave();
	cstk->c_f3expr = tn3;
	STRUCT_ASSIGN(cstk->c_fpos, curr_pos);
	STRUCT_ASSIGN(cstk->c_cfpos, csrc_pos);

	if (tn1 != NULL)
		expr(tn1, 0, 0);

	if (tn2 != NULL)
		tn2 = cconv(tn2);
	if (tn2 != NULL)
		tn2 = promote(NOOP, 0, tn2);
	if (tn2 != NULL && !issclt(tn2->tn_type->t_tspec)) {
		/* controlling expressions must have scalar type */
		error(204);
		tn2 = NULL;
	}
	if (tn2 != NULL)
		expr(tn2, 0, 1);

	if (tn2 == NULL) {
		cstk->c_infinite = 1;
	} else if (tn2->tn_op == CON) {
		if (isityp(tn2->tn_type->t_tspec)) {
			cstk->c_infinite = tn2->tn_val->v_quad != 0;
		} else {
			cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0;
		}
	}

	/* Checking the reinitialisation expression is done in for2() */

	reached = 1;
}
示例#4
0
/*
 * T_IF T_LPARN expr T_RPARN
 */
void
if1(tnode_t *tn)
{

	if (tn != NULL)
		tn = cconv(tn);
	if (tn != NULL)
		tn = promote(NOOP, 0, tn);
	expr(tn, 0, 1);
	pushctrl(T_IF);
}
示例#5
0
/********************************************//**
\brief Compute Fast Wavelet Transform (FWT) on 1D array
\param array : input array (1D)
\param filter : name of the filter to use (from TransformationType enum)
\param result : resulting transformed array
\param stop : flag indicating if we need to stop the process or not
\return boolean true if the execution is finished,
        false if the process has been stopped during the execution
***********************************************/
bool FWT::fastWaveletTransf(const std::vector<float>& array,
                            const TransformationType filter,
                            std::vector<float>& result,
                            bool* stop)
{
    std::vector<float> fw = array;//(array.begin(), array.end());
    
    // Get filters
    std::deque<float> h, g;
    compute_wavelet_filters(filter, h, g);
    
    // Make sure input is dyadic
    makeDyadic(fw);
    
    // Compute FWT
    int Jmax = log2((float)fw.size()) - 1;
    int Jmin = 0;
    for(int j = Jmax; j >= Jmin; --j)
    {
        if(*stop)
        {
            return false;
        }
        std::vector<float> A(&fw[0], &fw[pow(2.,j+1)]);
        std::vector<float> Coarse = subsampling(cconv(A, h));
        std::vector<float> Detail = subsampling(cconv(A, g));
        std::vector<float> coeff = Coarse;
        coeff.insert(coeff.end(), Detail.begin(), Detail.end());
        
        for(int k = 0; k < pow(2., j+1); ++k)
        {
            if(*stop)
            {
                return false;
            }
            fw[k] = coeff[k];
        }
    }
    result = fw;
    return true;
}
示例#6
0
void cls_object_draw_point(t_object *object)
{
	t_context *C=ctx_get();
	t_draw *draw=C->draw;
	glPushMatrix();

		glTranslatef(object->loc[0],object->loc[1],object->loc[2]);
		glScalef(object->size[0],object->size[1],object->size[2]);

		int size;
		float p[3]={0,0,0};
		//float black[3]={0,0,0};
		float white[3]={1,1,1};
		float red[3]={1,0,0};
		float green[3]={.2,1,.1};
		float cc[3];
		float *color;


		if(draw->mode==mode_selection)
		{
			size=10;
			cconv(cc,object->idcol);
			color=cc;
			//vprint3i(object->idcol,'\n');
		}
		else
		{
			if(object->is_selected)
			{
				color=green;
				size=20;
				object->loc[0]+=C->app->mouse->delta_x*.1;
			}
			else if(object->hover)
			{
				color=red;
				size=10;
			}
			else
			{
				color=white;
				size=1;
			}
		}

		skt_point(p,size,color);

	glPopMatrix();
}
示例#7
0
/*
 * T_SWITCH T_LPARN expr T_RPARN
 */
void
switch1(tnode_t *tn)
{
	tspec_t	t;
	type_t	*tp;

	if (tn != NULL)
		tn = cconv(tn);
	if (tn != NULL)
		tn = promote(NOOP, 0, tn);
	if (tn != NULL && !isityp(tn->tn_type->t_tspec)) {
		/* switch expression must have integral type */
		error(205);
		tn = NULL;
	}
	if (tn != NULL && tflag) {
		t = tn->tn_type->t_tspec;
		if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) {
			/* switch expr. must be of type `int' in trad. C */
			warning(271);
		}
	}

	/*
	 * Remember the type of the expression. Because its possible
	 * that (*tp) is allocated on tree memory the type must be
	 * duplicated. This is not too complicated because it is
	 * only an integer type.
	 */
	if ((tp = calloc(1, sizeof (type_t))) == NULL)
		nomem();
	if (tn != NULL) {
		tp->t_tspec = tn->tn_type->t_tspec;
		if ((tp->t_isenum = tn->tn_type->t_isenum) != 0)
			tp->t_enum = tn->tn_type->t_enum;
	} else {
		tp->t_tspec = INT;
	}

	expr(tn, 1, 0);

	pushctrl(T_SWITCH);
	cstk->c_switch = 1;
	cstk->c_swtype = tp;

	reached = rchflg = 0;
	ftflg = 1;
}
示例#8
0
文件: draw.c 项目: colinbouvry/minuit
void draw_init(t_draw *draw)
{
	float c[4];
	bzero(c,4);
	cconv(c,draw->background_color);

	// clear
	if(draw->with_clear)
	{
		draw_clear(c[0],c[1],c[2],0);
	}

	// set depth
	if(draw->with_depth)
		glEnable(GL_DEPTH_TEST);
	else
		glDisable(GL_DEPTH_TEST);
	
	// polygon offset
	if(draw->with_polygon_offset)
	{
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(1.0,1.0);
	}
	else
	{
		glDisable(GL_POLYGON_OFFSET_FILL);
	}

	if(draw->with_blend)
	{
		glEnable(GL_BLEND);
    		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
	{
		glDisable(GL_BLEND);
	}

	t_context *C = ctx_get();
	C->event->ui.use_line_global_width = 1;
	skt_update( C);

}
示例#9
0
/*
 * do stmnt do_while_expr
 * do error
 */
void
do2(tnode_t *tn)
{

	/*
	 * If there was a continue statement the expression controlling the
	 * loop is reached.
	 */
	if (cstk->c_cont)
		reached = 1;

	if (tn != NULL)
		tn = cconv(tn);
	if (tn != NULL)
		tn = promote(NOOP, 0, tn);
	if (tn != NULL && !issclt(tn->tn_type->t_tspec)) {
		/* controlling expressions must have scalar type */
		error(204);
		tn = NULL;
	}

	if (tn != NULL && tn->tn_op == CON) {
		if (isityp(tn->tn_type->t_tspec)) {
			cstk->c_infinite = tn->tn_val->v_quad != 0;
		} else {
			cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
		}
		if (!cstk->c_infinite && cstk->c_cont)
		    error(323);
	}

	expr(tn, 0, 1, 1);

	/*
	 * The end of the loop is only reached if it is no endless loop
	 * or there was a break statement which could be reached.
	 */
	reached = !cstk->c_infinite || cstk->c_break;
	rchflg = 0;

	popctrl(T_DO);
}
示例#10
0
文件: luachrrs.c 项目: ivanszl/chrrs
static int luacconv(lua_State *L)
{
	cconv_t cd;
	const char *fromcode, *tocode, *str;
	char *outstr, *p;
	size_t	inlen, outlen, size;

	if (lua_gettop(L) != 3)
	{
		lua_pushstring(L, "Bad argument number");
		lua_error(L);
		return 1;
	}

	fromcode = lua_tostring(L, 1);
	tocode = lua_tostring(L, 2);
	str = lua_tolstring(L, 3, &inlen);
	if((cd = cconv_open(tocode, fromcode)) == (cconv_t)(-1)) {
		lua_pushstring(L, str);
		return 1;
	}
	outlen = 3 * inlen;
	outstr = p = (char *)malloc(outlen);

	cm_memzero(outstr, outlen);

	size = cconv(cd, (const char **)&str, &inlen, &p, &outlen);
	cconv_close(cd);
	if (size == (size_t)(-1))
	{
		lua_pushstring(L, str);
		free(outstr);
		return 1;
	}
	lua_pushstring(L, outstr);
	free(outstr);
	return 1;
}
示例#11
0
void
mkinit(tnode_t *tn)
{
	ptrdiff_t offs;
	sym_t	*sym;
	tspec_t	lt, rt;
	tnode_t	*ln;
	struct	mbl *tmem;
	scl_t	sc;

	if (initerr || tn == NULL)
		goto end;

	sc = initsym->s_scl;

	/*
	 * Do not test for automatic aggregat initialisation. If the
	 * initializer starts with a brace we have the warning already.
	 * If not, an error will be printed that the initializer must
	 * be enclosed by braces.
	 */

	/*
	 * Local initialisation of non-array-types with only one expression
	 * without braces is done by ASSIGN
	 */
	if ((sc == AUTO || sc == REG) &&
	    initsym->s_type->t_tspec != ARRAY && initstk->i_nxt == NULL) {
		ln = getnnode(initsym, 0);
		ln->tn_type = tduptyp(ln->tn_type);
		ln->tn_type->t_const = 0;
		tn = build(ASSIGN, ln, tn);
		expr(tn, 0, 0);
		goto end;
	}

	/*
	 * Remove all entries which cannot be used for further initializers
	 * and do not require a closing brace.
	 */
	popinit(0);

	/* Initialisations by strings are done in strginit(). */
	if (strginit(tn))
		goto end;

	nextinit(0);
	if (initerr || tn == NULL)
		goto end;

	initstk->i_cnt--;

	/* Create a temporary node for the left side. */
	ln = tgetblk(sizeof (tnode_t));
	ln->tn_op = NAME;
	ln->tn_type = tduptyp(initstk->i_type);
	ln->tn_type->t_const = 0;
	ln->tn_lvalue = 1;
	ln->tn_sym = initsym;		/* better than nothing */

	tn = cconv(tn);

	lt = ln->tn_type->t_tspec;
	rt = tn->tn_type->t_tspec;

	if (!issclt(lt))
		lerror("mkinit() 1");

	if (!typeok(INIT, 0, ln, tn))
		goto end;

	/*
	 * Store the tree memory. This is nessesary because otherwise
	 * expr() would free it.
	 */
	tmem = tsave();
	expr(tn, 1, 0);
	trestor(tmem);

	if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) {
		/*
		 * Bit-fields can be initialized in trad. C only by integer
		 * constants.
		 */
		if (tflag)
			/* bit-field initialisation is illegal in trad. C */
			warning(186);
	}

	if (lt != rt || (initstk->i_type->t_isfield && tn->tn_op == CON))
		tn = convert(INIT, 0, initstk->i_type, tn);

	if (tn != NULL && tn->tn_op != CON) {
		sym = NULL;
		offs = 0;
		if (conaddr(tn, &sym, &offs) == -1) {
			if (sc == AUTO || sc == REG) {
				/* non-constant initializer */
				(void)gnuism(177);
			} else {
				/* non-constant initializer */
				error(177);
			}
		}
	}

 end:
	tfreeblk();
}
示例#12
0
文件: Mfxdecon.c 项目: 1014511134/src
int main(int argc, char *argv[])
{
    int n1;			/* number of samples in input trace	 */
    int n1w;		/* number of samples in time window      */
    int N1w;	       	/* number of time windows		*/
    int n1ws;	       	/* number of samples in window (wo taper)*/
    int n1wf;	       	/* number of samples in first window     */
    int n1wi;	       	/* number of samples in intermed. window */
    int n1taper;	       	/* number of samples in taper		*/
    int n2;	       		/* number of input traces		*/
    int n3;	       		/* number of input sections		*/
    int n2w;	       	/* number of traces in window		*/
    int N2w;	       	/* number of spacial windows		*/
    int n2wu;	       	/* updated number of traces in window	*/
    int nfft;		/* transform length			*/
    int nf;			/* number of frequencies		*/
    int lenf;		/* number of traces for filter		*/
    int i2w,i2,jr,itt;	/* summation indexes			*/
    int i1,i3,i1w,ifq,ir;	/* summation indexes			*/
    int ig,ifv;		/* summation indexes			*/
    bool verb;		/* flag to get advisory messages	*/
    int *ipvt;		/* indices of pivot permutations	*/

    float *info;		/* index of last zero pivot		*/
    float dt;		/* sampling interval in secs		*/
    float df;		/* sample interval in Hz		*/
    float fmin;		/* minimum frequency to process in Hz	*/
    float fmax;		/* maximum frequency to process in Hz	*/
    float taper;		/* length of taper			*/
    float twlen;       	/* time window length 			*/
    float **tracein;      	/* real trace			   	*/
    float **traceout;     	/* real trace			   	*/
    float *traceintw;       /* real trace in time window - input   	*/
    float *traceinttw;      /* real trace in time window - input   	*/
    float *traceotw;       	/* real trace in time window - output   */
    float *traceottw;      	/* real trace in time window - output   */
    float *rauto;       	/* real part of autocorrelation   	*/
    float *iauto;       	/* imaginary part of autocorretation 	*/
    float **cautom;      	/* complex autocorrelation matrix	*/
    float *aav;       	/* advanced autocorrelation vector	*/

    kiss_fft_cpx *cdata;	/* complex transformed trace (window)  	*/
    kiss_fft_cpx **fdata;	/* data - freq. domain          	*/
    kiss_fft_cpx **fdataw;	/* data - freq. domain - in window     	*/
    kiss_fft_cpx *sfv;	/* single frequency vector 	  	*/
    kiss_fft_cpx **ffv;	/* filtered frequency vector 	  	*/
    kiss_fft_cpx *fv;	/* frequency vector		      	*/
    kiss_fft_cpx *sfvout;	/* single frequency output vector      	*/
    kiss_fft_cpx *sfvcj;	/* complex conjugate of sfv	  	*/
    kiss_fft_cpx *acorr;	/* autocorrelation output	  	*/
    kiss_fft_cpx *filter;	/* filter               	  	*/

    kiss_fftr_cfg forw, invs;
    sf_file in, out;

    sf_init(argc,argv);

    in = sf_input("in");
    out = sf_output("out");

    if(!sf_getbool("verb",&verb)) verb=false;
    /* flag to get advisory messages */
	
    if(!sf_histint(in, "n1", &n1))  sf_error("No n1 in input");  if (verb) sf_warning("n1 = %i",n1);
    if(!sf_histfloat(in, "d1", &dt)) sf_error("No d1 in input"); if (verb) sf_warning("dt= %f",dt);
    if(!sf_histint(in,"n2",&n2))   sf_error("No n2 in input");   if (verb) sf_warning("n2= %f",n2);
    if(!sf_histint(in,"n3",&n3))   n3=1; if (verb) sf_warning("n3= %f",n3);

    if(!sf_getfloat("taper",&taper)) taper=.1;
    /* length of taper */
    if (taper==0.0) taper=.004; 

    if(!sf_getfloat("fmin",&fmin)) fmin=1.;    
    /* minimum frequency to process in Hz */
    if (fmin==0.0)  if (verb) sf_warning("using fmin=1 Hz");

    if(!sf_getfloat("fmax",&fmax)) fmax=1./(2*dt); 
    /* maximum frequency to process in Hz */
    if (fmax==0.0) if (verb) sf_warning("using fmax=1/(2*dt) Hz");

    if (!sf_getfloat("twlen", &twlen)) twlen=(float)(n1-1)*dt;
    /* time window length */
    if (twlen<.3) {
	twlen=.3; if (verb) sf_warning("twlen cannot be less than .3s, using .3s");
    }
    /* setting taper and spatial and temporal windows */
    n1taper =roundf(taper/dt);
    n1taper = (n1taper%2 ? n1taper+1 : n1taper); 

    N1w = roundf((n1-1)*dt/twlen);

    if (N1w==1) taper=0.0;

    n1ws = roundf(twlen/dt) + 1;
    n1wf = n1ws + n1taper/2;
    n1wi = n1ws + n1taper;

    if (!sf_getint("n2w", &n2w)) n2w=10;
    /* number of traces in window */
    if (!n2w) {
	n2w = 10;
	if (verb) sf_warning("n2w cannot be zero, using 10 traces");
    }	
    if (verb) sf_warning("n2w = %i",n2w);

    n2wu = n2w;

    if (!sf_getint("lenf", &lenf)) lenf=4; 
    /* number of traces for filter */
    if (!lenf) if (verb) sf_warning("using lenf=4");	
	
    N2w = n2/n2w;

    /* Computute FFT optimization number */
    nfft = 2*kiss_fft_next_fast_size((n1wf+1)/2);

    forw = kiss_fftr_alloc(nfft,0,NULL,NULL);
    invs = kiss_fftr_alloc(nfft,1,NULL,NULL);

    nf = nfft/2 + 1;
    df = 1.0/(nfft*dt);

    /* space allocation */
    cdata 	= (kiss_fft_cpx*) sf_complexalloc(nfft);
    traceintw =sf_floatalloc(nfft);
    traceinttw=sf_floatalloc(nfft);
    fdata   =(kiss_fft_cpx**) sf_complexalloc2(nf,n2);
    fdataw  =(kiss_fft_cpx**) sf_complexalloc2(nf,2*n2w+2*lenf);
    tracein = sf_floatalloc2(n1,n2);
    traceout= sf_floatalloc2(n1,n2);
    sfv   = (kiss_fft_cpx*) sf_complexalloc(2*n2w+2*lenf);
    sfvcj = (kiss_fft_cpx*) sf_complexalloc(2*n2w+2*lenf);
    acorr= (kiss_fft_cpx*) sf_complexalloc(lenf+1);
    rauto  = sf_floatalloc(lenf+1);
    iauto  = sf_floatalloc(lenf+1);
    cautom = sf_floatalloc2(2*lenf,2*lenf);
    aav = sf_floatalloc(2*lenf);
    filter = (kiss_fft_cpx*) sf_complexalloc(2*lenf+1);
    ffv   = (kiss_fft_cpx**) sf_complexalloc2(nf,2*n2w);
    sfvout=(kiss_fft_cpx*) sf_complexalloc(2*n2w);
    fv   =(kiss_fft_cpx*) sf_complexalloc(nfft);
    traceotw = sf_floatalloc(nfft);
    traceottw= sf_floatalloc(nfft);
    ipvt 	= sf_intalloc(4*n2w);
    info	= sf_floatalloc(4*n2w);

    /* zero output file */
    memset((void *) traceout[0], 0, n2*n1*sizeof(float));


    for (i3=0;i3<n3;i3++)
    {
    /* load traces into the zero-offset array and close tmpfile */
    sf_floatread(tracein[0],n1*n2,in);	
	
    /* If dt not set, issue advisory on frequency step df */
    if (dt && verb) sf_warning("df=%f", 1.0/(nfft*dt));

    if (verb) sf_warning("nf=%i, df=%f, nfft=%i, n1taper=%i", nf,df,nfft,n1taper);

    /* loop over time windows */
    for (i1w=0;i1w<N1w;i1w++) {

	if (i1w>0 && i1w<N1w-1) n1w=n1wi; 
	else if (i1w==0) 
	    if (N1w>1) n1w = n1wf;
	    else        n1w = n1;
	else
	    n1w = n1 - n1ws*i1w + n1taper/2;
 
	if (verb) sf_warning("i1w=%i, N1w=%i, n1w=%i, twlen=%f", i1w,N1w,n1w,twlen); 

	/* zero fdata */
	memset((void *) fdata[0], 0, nf*n2*sizeof(kiss_fft_cpx));
     
	/* select data */
	for (i2=0;i2<n2;i2++) {
 
	    if (i1w>0)
		for (i1=0;i1<n1w;i1++)
		    traceintw[i1]=tracein[i2][i1 + i1w*n1ws - n1taper/2];
	    else
		for (i1=0;i1<n1w;i1++)  
		    traceintw[i1]=tracein[i2][i1];	  

	    memset((void *) (traceintw + n1w), 0, (nfft-n1w)*sizeof(float));
	    memset((void *) cdata, 0, nfft*sizeof(kiss_fft_cpx));

	    /* FFT from t to f */
	    for (i1=0;i1<nfft;i1++)
		traceinttw[i1]=(i1%2 ? -traceintw[i1] : traceintw[i1]);
	    kiss_fftr(forw, traceinttw, cdata);

	    /* Store values */    
	    for (ifq = 0; ifq < nf; ifq++) { 
		fdata[i2][ifq] = cdata[nf-1-ifq];
	    }
	}

	/* Loop over space windows */
	for (i2w=0;i2w<N2w;i2w++){

	    /* to take care of a possible incomplete last window */
	    if (n2<i2w*n2w+2*n2w) 
		n2wu = n2 - i2w*n2w;
	    else
		n2wu = n2w;

	    if (verb) {
		sf_warning("i2w=%i, n2=%i, n2w=%i",
			   i2w,n2,n2w);
		sf_warning("n2wu=%i, N2w=%i, lenf=%i",
			   n2wu,N2w,lenf);
	    }

	    /* zero fdataw */
	    for (i2=0;i2<n2w+2*lenf;i2++)
		memset((void *) fdataw[i2], 0, nf*sizeof(kiss_fft_cpx));

	    /* select data */
	    for (i2=0;i2<n2wu+2*lenf;i2++) 
		for (ifq = 0; ifq < nf; ifq++) {

		    if (i2w>0 && i2w<N2w-1)  
			fdataw[i2][ifq] = fdata[i2 + i2w*n2w - lenf][ifq];
		    else if (i2w==0)
			if (i2>=lenf && i2<n2w+lenf) 
			    fdataw[i2][ifq] = fdata[i2 - lenf][ifq];
			else if (i2<lenf) 
			    fdataw[i2][ifq] = fdata[0][ifq];
			else 
			    if (N2w>1) 
				fdataw[i2][ifq] = fdata[i2 - lenf][ifq];
			    else 
				fdataw[i2][ifq] = fdata[n2-1][ifq];
		    else
			if (i2<n2wu+lenf)
			    fdataw[i2][ifq] = fdata[i2 + i2w*n2w - lenf][ifq];
			else 
			    fdataw[i2][ifq] = fdata[n2-1][ifq];
		}

	    /* loop over frequencies */
	    for (ifq=0;ifq<nf;ifq++) {

		if ((float)ifq*df>=fmin && (float)ifq*df<=fmax) {

		    /* Loop over space window */
		    memset((void *) sfv, 0, (n2wu+2*lenf)*sizeof(kiss_fft_cpx));
		    memset((void *) sfvcj, 0, (n2wu+2*lenf)*sizeof(kiss_fft_cpx));

		    for (i2=0;i2<n2wu+2*lenf;i2++) {
	  
			sfv[i2]=fdataw[i2][ifq];
			sfvcj[i2]=sf_conjf(fdataw[i2][ifq]);
		    }

		    memset((void *) acorr, 0, (lenf+1)*sizeof(kiss_fft_cpx));

		    /* complex autocorrelation */
		    cxcor(n2wu,0,sfv,n2wu,0,sfv,lenf+1,0,acorr);

		    /* zeroing files */
		    memset((void *) rauto, 0, (lenf+1)*sizeof(float));
		    memset((void *) iauto, 0, (lenf+1)*sizeof(float));

		    /* taking real and imaginary parts */
		    for (i2=0;i2<lenf+1;i2++) {
			rauto[i2]=acorr[i2].r;
			iauto[i2]=acorr[i2].i;
		    }

		    /* zeroing files */
		    memset((void *) aav, 0, 2*lenf*sizeof(float));
		    memset((void *) filter, 0, (2*lenf+1)*sizeof(kiss_fft_cpx));
		    for (ir=0;ir<2*lenf;ir++) 
			memset((void *) cautom[ir], 0, 2*lenf*sizeof(float));

		    /* matrix problem */
		    for (ir=0;ir<lenf;ir++) 
			for (jr=0;jr<lenf;jr++) { 
			    if (ir>=jr) cautom[ir][jr]=acorr[ir-jr].r;
			    else        cautom[ir][jr]=acorr[jr-ir].r;
			}

		    for (ir=lenf;ir<2*lenf;ir++)
			for (jr=0;jr<lenf;jr++) {
			    if (ir-lenf<jr) cautom[ir][jr]=-acorr[jr-ir+lenf].i;
			    else            cautom[ir][jr]= acorr[ir-jr-lenf].i;
			}

		    for (ir=lenf;ir<2*lenf;ir++)
			for (jr=lenf;jr<2*lenf;jr++)
			    cautom[ir][jr]=cautom[ir-lenf][jr-lenf];

		    for (ir=0;ir<lenf;ir++)
			for (jr=lenf;jr<2*lenf;jr++)
			    cautom[ir][jr]=-cautom[ir+lenf][jr-lenf];

		    for (ig=0;ig<2*lenf;ig++) {
			if (ig<lenf) aav[ig]=acorr[ig+1].r;
			else aav[ig]=acorr[ig-lenf+1].i;
		    }

		    lu_decomposition(2*lenf,cautom,ipvt,info);
		    backward_substitution(2*lenf,cautom,ipvt,aav);
      
		    /* construct filter */
		    for (ifv=0,ig=lenf-1;ifv<lenf;ifv++,ig--) 
			filter[ifv]=sf_conjf(cmplx(aav[ig]/2.,aav[ig+lenf]/2.));

		    for (ifv=lenf+1,ig=0;ifv<2*lenf+1;ifv++,ig++) 
			filter[ifv]=cmplx(aav[ig]/2.,aav[ig+lenf]/2.);
	 
		    memset((void *) sfvout, 0, n2wu*sizeof(kiss_fft_cpx));

		    /* convolution of data with filter */
		    /* output is one sample ahead */
		    cconv(n2wu+2*lenf,-lenf,sfv,2*lenf+1,-lenf,filter,n2wu,0,sfvout); 

		    /* store filtered values */
		    for (i2=0;i2<n2wu;i2++) ffv[i2][ifq]=sfvout[i2];

		}
	    } /* end of frequencies loop */

	    /* loop along space windows */
	    for (i2=0;i2<n2wu;i2++) {
    
		/* select data */
		for (ifq=0,itt=nf-1;ifq<nf;ifq++,itt--)
		    fv[ifq] = ffv[i2][itt]; 

		memset((void *) (fv+nf), 0, (nfft-nf)*sizeof(kiss_fft_cpx));
		memset((void *) traceotw, 0, nfft*sizeof(float));

		/* FFT back from f to t and scaling */
		kiss_fftri(invs,fv,traceotw);
		for (i1=0;i1<SF_MIN(n1,nfft);i1++)
		    traceotw[i1]/=nfft; 
		for (i1=0;i1<SF_MIN(n1,nfft);i1++)
		    traceottw[i1]=(i1%2 ? -traceotw[i1] : traceotw[i1]); 
      
		/*loop along time */
		if (N1w>1) {
		    /* first portion of time window */
		    if (i1w>0) 
			for (i1=0;i1<n1taper;i1++)
			    traceout[i2w*n2w+i2][i1+i1w*n1ws-n1taper/2]+=
				traceottw[i1]*((float)(i1)*dt/taper);
		    else 
			for (i1=0;i1<n1taper;i1++)
			    traceout[i2w*n2w+i2][i1]=traceottw[i1];

		    /* intermediate portion of time window */
		    if (i1w>0) 
			for (i1=n1taper;i1<n1w-n1taper;i1++)
			    traceout[i2w*n2w+i2][i1+i1w*n1ws-n1taper/2]=traceottw[i1];
		    else 
			for (i1=n1taper;i1<n1w-n1taper;i1++)
			    traceout[i2w*n2w+i2][i1]=traceottw[i1];

		    /* last portion of time window */
		    if (i1w>0 && i1w<N1w-1) 
			for (i1=n1w-n1taper;i1<n1w;i1++)
			    traceout[i2w*n2w+i2][i1+i1w*n1ws-n1taper/2]+=
				traceottw[i1]*(1.-((float)(i1-n1w+n1taper))*dt/taper);
		    else if (i1w==N1w-1)
			for (i1=n1w-n1taper;i1<n1w;i1++)
			    traceout[i2w*n2w+i2][i1+i1w*n1ws-n1taper/2]=traceottw[i1];
		    else 
			for (i1=n1w-n1taper;i1<n1w;i1++)
			    traceout[i2w*n2w+i2][i1]+=traceottw[i1]*(1.-((float)(i1-n1w+n1taper))*dt/taper);
		}
		else {
		    for (i1=0;i1<n1;i1++) 
			traceout[i2w*n2w+i2][i1]=traceottw[i1];
		}

	    } /* end loop over space windows */

	} /* end loop over space windows */

    } /* end of time windows loop */
 
    /* Write output data to file */
    sf_floatwrite(traceout[0], n1*n2, out);
    if(verb) sf_warning("I3=%d is done!\n",i3+1);
    }

    /* Free allocated memory */
    free(traceintw);
    free(traceinttw);
    free(fdataw[0]);
    free(fdataw);
    free(sfv);
    free(sfvcj);
    free(acorr);
    free(rauto);
    free(iauto);
    free(cautom[0]);
    free(cautom);
    free(aav);
    free(filter);
    free(sfvout);
    free(fv);
    free(traceotw);
    free(traceottw);
    free(ffv[0]);
    free(ffv);
    free(tracein[0]);
    free(tracein);
    free(traceout[0]);
    free(traceout);

    exit(0);
}