1 /*--------------------------------------------------------------------
2  *
3  *	Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
4  *	See LICENSE.TXT file for copying and redistribution conditions.
5  *
6  *	This program is free software; you can redistribute it and/or modify
7  *	it under the terms of the GNU Lesser General Public License as published by
8  *	the Free Software Foundation; version 3 or any later version.
9  *
10  *	This program is distributed in the hope that it will be useful,
11  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *	GNU Lesser General Public License for more details.
14  *
15  *	Contact info: www.generic-mapping-tools.org
16  *--------------------------------------------------------------------*/
17 /*
18  *  Structures in support of FFT use.
19  *
20  * Author:	P. Wessel, derived from W.H.F. Smith implementation
21  * Date:	12-FEB-2013
22  * Version:	6 API
23  *
24  */
25 
26 /*!
27  * \file gmt_fft.h
28  * \brief Structures in support of FFT use.
29  */
30 
31 #ifndef GMT_FFT_H
32 #define GMT_FFT_H
33 #ifdef __APPLE__ /* Accelerate framework */
34 #include <Accelerate/Accelerate.h>
35 #endif
36 
37 enum GMT_FFT_EXTEND {
38 	GMT_FFT_EXTEND_POINT_SYMMETRY = 0,
39 	GMT_FFT_EXTEND_MIRROR_SYMMETRY,
40 	GMT_FFT_EXTEND_NONE,
41 	GMT_FFT_EXTEND_NOT_SET};
42 
43 enum GMT_FFT_TREND {
44 	GMT_FFT_REMOVE_NOT_SET = -1,
45 	GMT_FFT_REMOVE_NOTHING = 0,
46 	GMT_FFT_REMOVE_MEAN,
47 	GMT_FFT_REMOVE_MID,
48 	GMT_FFT_REMOVE_TREND};
49 
50 enum GMT_FFT_KCHOICE {
51 	GMT_FFT_K_IS_KX = 0,
52 	GMT_FFT_K_IS_KY,
53 	GMT_FFT_K_IS_KR};
54 
55 enum GMT_FFT_DIMSET {
56 	GMT_FFT_UNSPECIFIED = 0,
57 	GMT_FFT_EXTEND,
58 	GMT_FFT_FORCE,
59 	GMT_FFT_SET,
60 	GMT_FFT_LIST};
61 
62 enum GMT_FFT_SUGGEST {	/* Indices for struct GMT_FFT_SUGGESTION arrays */
63 	GMT_FFT_FAST = 0,
64 	GMT_FFT_ACCURATE,
65 	GMT_FFT_STORAGE,
66 	GMT_FFT_N_SUGGEST};
67 
68 /*! Holds parameters needed to calculate kx, ky, kr */
69 struct GMT_FFT_WAVENUMBER {
70 	int nx2, ny2;
71 	unsigned int dim;	/* FFT dimension as setup by Init */
72 	double delta_kx, delta_ky;
73 	double (*k_ptr) (uint64_t k, struct GMT_FFT_WAVENUMBER *K);	/* pointer to function returning either kx, ky, or kr */
74 	double coeff[3];		/* Detrending coefficients returned, if used */
75 	struct GMT_FFT_INFO *info;	/* Pointer back to GMT_FFT_INFO */
76 };
77 
78 struct GMT_FFT_INFO {
79 	bool set;			/* true if we parsed options; false we must take default settings */
80 	bool save[2];			/* save[GMT_IN] means save the input grid just before calling the FFT */
81 					/* save[GMT_OUT] means save the complex output grid just after calling the FFT */
82 	bool polar;			/* true if we are to save the complex output grid in polar form */
83 	bool verbose;			/* true if we are to report FFT suggestions */
84 	char suffix[GMT_LEN64];		/* Suffix used to form output names if save[GMT_IN] is true [tapered] */
85 	unsigned int n_columns;		/* Desired hard FFT n_columns dimensionl or 0 if free to adjust */
86 	unsigned int n_rows;		/* Desired hard FFT n_rows dimensionl or 0 if free to adjust */
87 	unsigned int taper_mode;	/* One of the GMT_FFT_EXTEND for extension/mirroring */
88 	unsigned int info_mode;		/* One of the GMT_FFT_INFO for setting n_columns/n_rows or inquire */
89 	unsigned int suggest;		/* Index into dimension suggestions [0 = pick best] */
90 	int trend_mode;			/* One of the GMT_FFT_TREND for handling detrending */
91 	double taper_width;		/* Amount of tapering in percent */
92 	struct GMT_FFT_WAVENUMBER *K;	/* Pointer to wavenumber structure */
93 };
94 
95 struct GMT_FFT_SUGGESTION {
96 	unsigned int n_columns;
97 	unsigned int n_rows;
98 	size_t worksize;	/* # single-complex elements needed in work array  */
99 	size_t totalbytes;	/* (8*(n_columns*n_rows + worksize))  */
100 	double run_time;
101 	double rms_rel_err;
102 }; /* [0] holds fastest, [1] most accurate, [2] least storage  */
103 
104 
105 struct GMT_FFT_HIDDEN {	/* Items needed by various FFT packages */
106 	unsigned int n_1d, n_2d;	/* Bill Gates says: error C2016: C requires that a struct or union has at least one member */
107 #ifdef __APPLE__ /* Accelerate framework */
108 	FFTSetup setup_1d, setup_2d;
109 	DSPSplitComplex dsp_split_complex_1d;
110 	DSPSplitComplex dsp_split_complex_2d;
111 #endif
112 };
113 
114 #endif
115