fft2_filt.c 1.96 KB
Newer Older
niklas.thiel's avatar
niklas.thiel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*-----------------------------------------------------------------------------------------
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
 *
 * This file is part of IFOS.
 *
 * IFOS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 *
 * IFOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   2D-FFT preparation
 *  ----------------------------------------------------------------------*/

#include "fd.h"

void	fft2(float **array, float **arrayim, int NYG, int NXG, int dir) {

		extern FILE *FP;
		
		COMPLEX	*C;
		int	j, i, k, nx, ny, nxy;
		float **RE, **IM;
		
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
33 34 35 36 37 38 39 40
		char pf1[STRING_SIZE];
		FILE *file;
		extern char SEIS_FILE[STRING_SIZE];
			
		nx = NXG;
		ny = NYG;

		C = cplxvector(1, ny*nx);
niklas.thiel's avatar
niklas.thiel committed
41
		
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
42
	if (dir==1) {				
niklas.thiel's avatar
niklas.thiel committed
43 44

		k = 1;
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
45 46 47
		for (i=1;i<=nx;i++)
			for (j=1;j<=ny;j++) {
				C[k].re = array[j][i];
niklas.thiel's avatar
niklas.thiel committed
48 49 50
				C[k].im = 0.0;
				k++;
			}
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
51 52 53 54
		
		forward_fft2f(C, ny, nx);
		
		
niklas.thiel's avatar
niklas.thiel committed
55
		k = 1;
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
56 57 58 59
		for (i=1;i<=nx;i++)
			for (j=1;j<=ny;j++) {
				array[j][i] = C[k].re;
				arrayim[j][i] = C[k].im;
niklas.thiel's avatar
niklas.thiel committed
60 61
				k++;
			}
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
62

niklas.thiel's avatar
niklas.thiel committed
63
	} else {
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
64

niklas.thiel's avatar
niklas.thiel committed
65
		k = 1;
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
66 67 68 69
		for (i=1;i<=nx;i++)
			for (j=1;j<=ny;j++) {
				C[k].re = array[j][i];
				C[k].im = arrayim[j][i];
niklas.thiel's avatar
niklas.thiel committed
70 71
				k++;
			}
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
72 73
		inverse_fft2f(C, ny, nx);
		
niklas.thiel's avatar
niklas.thiel committed
74
		k = 1;
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
75 76 77 78
		for (i=1;i<=nx;i++)
			for (j=1;j<=ny;j++) {
				array[j][i] = C[k].re;
				arrayim[j][i] = 0.0;
niklas.thiel's avatar
niklas.thiel committed
79 80 81 82
				k++;
			}
	}
				
niklas.thiel's avatar
BUGFIX  
niklas.thiel committed
83 84
	free_cplxvector(C, 1, ny*nx);
}