1 | function rmavgssh(bryname,grdname,obc) |
---|
2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3 | % |
---|
4 | % Remove the averaged SSH in the boundary (bry) files. |
---|
5 | % |
---|
6 | % |
---|
7 | % Further Information: |
---|
8 | % http://www.brest.ird.fr/Roms_tools/ |
---|
9 | % |
---|
10 | % This file is part of ROMSTOOLS |
---|
11 | % |
---|
12 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
13 | % it under the terms of the GNU General Public License as published |
---|
14 | % by the Free Software Foundation; either version 2 of the License, |
---|
15 | % or (at your option) any later version. |
---|
16 | % |
---|
17 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
18 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | % GNU General Public License for more details. |
---|
21 | % |
---|
22 | % You should have received a copy of the GNU General Public License |
---|
23 | % along with this program; if not, write to the Free Software |
---|
24 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
25 | % MA 02111-1307 USA |
---|
26 | % |
---|
27 | % Copyright (c) 2001-2006 by Pierrick Penven |
---|
28 | % e-mail:Pierrick.Penven@ird.fr |
---|
29 | % |
---|
30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
31 | disp(' '); |
---|
32 | disp('Remove averaged SSH ...'); |
---|
33 | |
---|
34 | ng=netcdf(grdname); |
---|
35 | L=length(ng('xi_rho')); |
---|
36 | M=length(ng('eta_rho')); |
---|
37 | |
---|
38 | nc=netcdf(bryname,'write'); |
---|
39 | time=nc{'bry_time'}(:); |
---|
40 | tlen=length(time); |
---|
41 | |
---|
42 | |
---|
43 | for l=1:tlen |
---|
44 | %for l=1:1 |
---|
45 | tssh=0; |
---|
46 | S=0; |
---|
47 | for obcndx=1:4 |
---|
48 | if obc(obcndx)==1 |
---|
49 | if obcndx==1 |
---|
50 | pm=ng{'pm'}(1,:); |
---|
51 | pn=ng{'pn'}(1,:); |
---|
52 | rmask=ng{'mask_rho'}(1,:); |
---|
53 | suffix='_south'; |
---|
54 | elseif obcndx==2 |
---|
55 | pm=(ng{'pm'}(:,L))'; |
---|
56 | pn=(ng{'pn'}(:,L))'; |
---|
57 | rmask=(ng{'mask_rho'}(:,L))'; |
---|
58 | suffix='_east'; |
---|
59 | elseif obcndx==3 |
---|
60 | pm=ng{'pm'}(M,:); |
---|
61 | pn=ng{'pn'}(M,:); |
---|
62 | rmask=ng{'mask_rho'}(M,:); |
---|
63 | suffix='_north'; |
---|
64 | elseif obcndx==4 |
---|
65 | pm=(ng{'pm'}(:,1))'; |
---|
66 | pn=(ng{'pn'}(:,1))'; |
---|
67 | rmask=(ng{'mask_rho'}(:,1))'; |
---|
68 | suffix='_west'; |
---|
69 | end |
---|
70 | Nx=length(pm); |
---|
71 | ssh=nc{['zeta',suffix]}(l,:); |
---|
72 | tssh=tssh+sum(rmask.*ssh./(pm.*pn)); |
---|
73 | S=S+sum(rmask./(pm.*pn)); |
---|
74 | end |
---|
75 | end |
---|
76 | avgssh=tssh./S; |
---|
77 | for obcndx=1:4 |
---|
78 | if obc(obcndx)==1 |
---|
79 | if obcndx==1 |
---|
80 | suffix='_south'; |
---|
81 | elseif obcndx==2 |
---|
82 | suffix='_east'; |
---|
83 | elseif obcndx==3 |
---|
84 | suffix='_north'; |
---|
85 | elseif obcndx==4 |
---|
86 | suffix='_west'; |
---|
87 | end |
---|
88 | ssh=nc{['zeta',suffix]}(l,:); |
---|
89 | nc{['zeta',suffix]}(l,:)=ssh-avgssh; |
---|
90 | end |
---|
91 | end |
---|
92 | end |
---|
93 | close(ng) |
---|
94 | close(nc) |
---|