function varargout = thompsonbrazil(varargin)
%THOMPSONbrazil   Tidal-killer filter based on theory Thompson, 1983, JPO 13 (June), pp 1077-1083.
%
% f = thompsonbrazil             or
% f = thompsonbrazil('onesided') where f contains 121 of the 240 filter points,
%                                viz. w_0 to w_k of the symmetric filter
%                                w_{-k} to w_k, with k ranging to 120.
%
% f = thompsonbrazil('twosided') where f contains the whole 240-point filter
%                                w_{-k} to w_k, with k ranging to 120.
%
% [f,index] = thompsonbrazil(...) also returns the indexes k of the filter
%
% The filter can be applied on hourly timeseries as:
%
%   f             = thompsonbrazil('twosided');
%   dat           = filter(f,1,hourly_raw);
%   hourly_smooth = dat(length(f):end)
%
% Returns a filter based on theory in:
% 
%    Rory O.R.Y. Thompson, 1983. "Low-pass filters to suppress 
%    inertial and tidal frequencies", Journal of Physical Oceanography,
%    Volume 13, June, 1077-1083.
%
% Filter thompsonbrazil has been received from Raphel Nogueira of UFRJ as:
% 06-03-2006  11:12 1,031,680 Meteorological Tide.xls
%
% See also: FILTER, T_TIDE, GODIN

% This function is part of the OpenEarthTools initiative.

%   --------------------------------------------------------------------
%   Copyright (C) 2007 Delft University of Technology
%       Gerben J. de Boer
%
%       g.j.deboer@tudelft.nl	
%
%       Environmental Fluid Mechanics Section
%       Faculty of Civil Engineering and Geosciences
%       PO Box 5048
%       2600 GA Delft
%       The Netherlands
%
%   This library is free software; you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation; either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library 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
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library; if not, write to the Free Software
%   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
%   USA or 
%   http://www.gnu.org/licenses/licenses.html,
%   http://www.gnu.org/, http://www.fsf.org/
%   --------------------------------------------------------------------

sides = 'onesided';

if nargin>0
   sides = varargin{1};
end

dat=[...
-120.0	 0.00003552
-119.0	-0.00000925
-118.0	-0.00004102
-117.0	-0.00006383
-116.0	-0.00008226
-115.0	-0.00009834
-114.0	-0.00011189
-113.0	-0.00012273
-112.0	-0.00013209
-111.0	-0.00014145
-110.0	-0.00015020
-109.0	-0.00015462
-108.0	-0.00014971
-107.0	-0.00013236
-106.0	-0.00010334
-105.0	-0.00006628
-104.0	-0.00002477
-103.0	0.00001993
-102.0	0.00006852
-101.0	0.00012147
-100.0	0.00017725
-99.0	0.00023281
-98.0	0.00028588
-97.0	0.00033673
-96.0	0.00038753
-95.0	0.00043965
-94.0	0.00049117
-93.0	0.00053690
-92.0	0.00057090
-91.0	0.00058941
-90.0	0.00059171
-89.0	0.00057842
-88.0	0.00054899
-87.0	0.00050081
-86.0	0.00043084
-85.0	0.00033826
-84.0	0.00022575
-83.0	0.00009803
-82.0	-0.00004100
-81.0	-0.00019038
-80.0	-0.00035141
-79.0	-0.00052497
-78.0	-0.00070876
-77.0	-0.00089661
-76.0	-0.00108015
-75.0	-0.00125120
-74.0	-0.00140318
-73.0	-0.00153092
-72.0	-0.00162949
-71.0	-0.00169364
-70.0	-0.00171827
-69.0	-0.00169929
-68.0	-0.00163404
-67.0	-0.00152075
-66.0	-0.00135779
-65.0	-0.00114366
-64.0	-0.00087801
-63.0	-0.00056302
-62.0	-0.00020396
-61.0	0.00019141
-60.0	0.00061424
-59.0	0.00105542
-58.0	0.00150550
-57.0	0.00195382
-56.0	0.00238802
-55.0	0.00279467
-54.0	0.00316052
-53.0	0.00347357
-52.0	0.00372300
-51.0	0.00389828
-50.0	0.00398842
-49.0	0.00398234
-48.0	0.00387061
-47.0	0.00364730
-46.0	0.00331078
-45.0	0.00286295
-44.0	0.00230774
-43.0	0.00165013
-42.0	0.00089664
-41.0	0.00005697
-40.0	-0.00085459
-39.0	-0.00181912
-38.0	-0.00281451
-37.0	-0.00381758
-36.0	-0.00480524
-35.0	-0.00575433
-34.0	-0.00664045
-33.0	-0.00743698
-32.0	-0.00811530
-31.0	-0.00864615
-30.0	-0.00900138
-29.0	-0.00915531
-28.0	-0.00908532
-27.0	-0.00877211
-26.0	-0.00820002
-25.0	-0.00735758
-24.0	-0.00623812
-23.0	-0.00483974
-22.0	-0.00316507
-21.0	-0.00122078
-20.0	0.00098225
-19.0	0.00342832
-18.0	0.00609619
-17.0	0.00895892
-16.0	0.01198436
-15.0	0.01513614
-14.0	0.01837445
-13.0	0.02165653
-12.0	0.02493707
-11.0	0.02816917
-10.0	0.03130592
-9.0	0.03430211
-8.0	0.03711522
-7.0	0.03970549
-6.0	0.04203534
-5.0	0.04406940
-4.0	0.04577560
-3.0	0.04712722
-2.0	0.04810450
-1.0	0.04869503
0.0	0.04889249
1.0	0.04869503
2.0	0.04810450
3.0	0.04712722
4.0	0.04577560
5.0	0.04406940
6.0	0.04203534
7.0	0.03970549
8.0	0.03711522
9.0	0.03430211
10.0	0.03130592
11.0	0.02816917
12.0	0.02493707
13.0	0.02165653
14.0	0.01837445
15.0	0.01513614
16.0	0.01198436
17.0	0.00895892
18.0	0.00609619
19.0	0.00342832
20.0	0.00098225
21.0	-0.00122078
22.0	-0.00316507
23.0	-0.00483974
24.0	-0.00623812
25.0	-0.00735758
26.0	-0.00820002
27.0	-0.00877211
28.0	-0.00908532
29.0	-0.00915531
30.0	-0.00900138
31.0	-0.00864615
32.0	-0.00811530
33.0	-0.00743698
34.0	-0.00664045
35.0	-0.00575433
36.0	-0.00480524
37.0	-0.00381758
38.0	-0.00281451
39.0	-0.00181912
40.0	-0.00085459
41.0	0.00005697
42.0	0.00089664
43.0	0.00165013
44.0	0.00230774
45.0	0.00286295
46.0	0.00331078
47.0	0.00364730
48.0	0.00387061
49.0	0.00398234
50.0	0.00398842
51.0	0.00389828
52.0	0.00372300
53.0	0.00347357
54.0	0.00316052
55.0	0.00279467
56.0	0.00238802
57.0	0.00195382
58.0	0.00150550
59.0	0.00105542
60.0	0.00061424
61.0	0.00019141
62.0	-0.00020396
63.0	-0.00056302
64.0	-0.00087801
65.0	-0.00114366
66.0	-0.00135779
67.0	-0.00152075
68.0	-0.00163404
69.0	-0.00169929
70.0	-0.00171827
71.0	-0.00169364
72.0	-0.00162949
73.0	-0.00153092
74.0	-0.00140318
75.0	-0.00125120
76.0	-0.00108015
77.0	-0.00089661
78.0	-0.00070876
79.0	-0.00052497
80.0	-0.00035141
81.0	-0.00019038
82.0	-0.00004100
83.0	0.00009803
84.0	0.00022575
85.0	0.00033826
86.0	0.00043084
87.0	0.00050081
88.0	0.00054899
89.0	0.00057842
90.0	0.00059171
91.0	0.00058941
92.0	0.00057090
93.0	0.00053690
94.0	0.00049117
95.0	0.00043965
96.0	0.00038753
97.0	0.00033673
98.0	0.00028588
99.0	0.00023281
100.0	0.00017725
101.0	0.00012147
102.0	0.00006852
103.0	0.00001993
104.0	-0.00002477
105.0	-0.00006628
106.0	-0.00010334
107.0	-0.00013236
108.0	-0.00014971
109.0	-0.00015462
110.0	-0.00015020
111.0	-0.00014145
112.0	-0.00013209
113.0	-0.00012273
114.0	-0.00011189
115.0	-0.00009834
116.0	-0.00008226
117.0	-0.00006383
118.0	-0.00004102
119.0	-0.00000925
120.0	0.00003552
];

if     strcmpi(sides,'twosided')
   index = dat(      :,1);
   f     = dat(      :,2);
elseif strcmpi(sides,'onesided')
   index = dat(121:end,1);
   f     = dat(121:end,2);
else
   error(['invalid option: onesided or twosided, not ',sides])
end


if     nargout ==1
   varargout = {f};
elseif nargout ==2
   varargout = {f,index};
end

%% EOF