1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % |
---|
3 | % pathfinder_sst |
---|
4 | % |
---|
5 | % Interpolate PATHFINDER data on ROMS grid and write |
---|
6 | % into a ROMS netcdf forcing file |
---|
7 | % |
---|
8 | % Further Information: |
---|
9 | % http://www.brest.ird.fr/Roms_tools/ |
---|
10 | % |
---|
11 | % This file is part of ROMSTOOLS |
---|
12 | % |
---|
13 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
14 | % it under the terms of the GNU General Public License as published |
---|
15 | % by the Free Software Foundation; either version 2 of the License, |
---|
16 | % or (at your option) any later version. |
---|
17 | % |
---|
18 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
19 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | % GNU General Public License for more details. |
---|
22 | % |
---|
23 | % You should have received a copy of the GNU General Public License |
---|
24 | % along with this program; if not, write to the Free Software |
---|
25 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
26 | % MA 02111-1307 USA |
---|
27 | % |
---|
28 | % Copyright (c) 2003 by X. Capet (UCLA) and P. Marchesiello (IRD) |
---|
29 | % Contribution of P. Penven (IRD) |
---|
30 | % |
---|
31 | % Updated October-2006 by Pierrick Penven |
---|
32 | % (generalisation of romstool_param.m) |
---|
33 | % |
---|
34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
35 | close all |
---|
36 | clear all |
---|
37 | %%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%% |
---|
38 | % |
---|
39 | romstools_param |
---|
40 | % |
---|
41 | Roa=1e8; % extrapolation decay length scale |
---|
42 | default=0; |
---|
43 | icoarse=8; % resolution coef for coarse grid |
---|
44 | spval=NaN; % Missing value |
---|
45 | % |
---|
46 | %%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%% |
---|
47 | % |
---|
48 | % Read ROMS Grid |
---|
49 | % |
---|
50 | ncgrd=netcdf(grdname); |
---|
51 | latgrd=ncgrd{'lat_rho'}(:); % model grid |
---|
52 | longrd=ncgrd{'lon_rho'}(:); |
---|
53 | maskgrd=ncgrd{'mask_rho'}(:); |
---|
54 | maskgrd(maskgrd==0)=NaN; |
---|
55 | close(ncgrd) |
---|
56 | lonmin=min(min(longrd))-1; |
---|
57 | lonmax=max(max(longrd))+1; |
---|
58 | latmin=min(min(latgrd))-1; |
---|
59 | latmax=max(max(latgrd))+1; |
---|
60 | % |
---|
61 | % Create Grid for the PATHFINDER data |
---|
62 | % Extract a subdomain. |
---|
63 | % Extend 1 degree to ensure that the coarse grid |
---|
64 | % for land extrapolation is large enough |
---|
65 | % |
---|
66 | nc=netcdf(pathfinder_sst_name); |
---|
67 | LON=nc{'X'}(:); |
---|
68 | LAT=nc{'Y'}(:); |
---|
69 | imin=max(find(LON<lonmin)); |
---|
70 | imax=min(find(LON>lonmax)); |
---|
71 | jmin=max(find(LAT<latmin)); |
---|
72 | jmax=min(find(LAT>latmax)); |
---|
73 | LON=LON(imin:imax); |
---|
74 | LAT=LAT(jmin:jmax); |
---|
75 | [lon,lat]=meshgrid(LON,LAT); |
---|
76 | % |
---|
77 | % Create coarser grid for land extrapolation |
---|
78 | % |
---|
79 | LONTMP=LON(1:icoarse:end); |
---|
80 | LATTMP=LAT(1:icoarse:end); |
---|
81 | [lontmp,lattmp]=meshgrid(LONTMP,LATTMP); |
---|
82 | % |
---|
83 | % Do the Interpolation and fill missing values (NaN) |
---|
84 | % with extrapolated data. |
---|
85 | % |
---|
86 | ncfor=netcdf(frcname,'write'); |
---|
87 | for tindex=1:12 |
---|
88 | disp([' ... Month index: ',num2str(tindex)]) |
---|
89 | SST=squeeze(nc{'SST'}(tindex,jmin:jmax,imin:imax)); |
---|
90 | % |
---|
91 | % Found weird values (-3) in Louisiana (ice cubes ?) |
---|
92 | % |
---|
93 | SST(SST<0)=NaN; |
---|
94 | % |
---|
95 | SSTTMP=SST(1:icoarse:end,1:icoarse:end); |
---|
96 | if tindex==1 |
---|
97 | SSTTMP=get_missing_val(LONTMP,LATTMP,SSTTMP, ... |
---|
98 | spval,Roa,default,1); % 1 to save extrap |
---|
99 | else |
---|
100 | SSTTMP=get_missing_val(LONTMP,LATTMP,SSTTMP, ... |
---|
101 | spval,Roa,default,0); % 0 to load extrap |
---|
102 | end |
---|
103 | % |
---|
104 | % Interpolation from coarse PATHFINDER grid to ROMS grid |
---|
105 | % |
---|
106 | SSTTMPgrd=interp2(lontmp,lattmp,SSTTMP,longrd,latgrd,'linear'); |
---|
107 | % |
---|
108 | % Interpolation from fine PATHFINDER grid to ROMS grid |
---|
109 | % |
---|
110 | SSTgrd=interp2(lon,lat,SST,longrd,latgrd,'linear'); |
---|
111 | % |
---|
112 | % Replace NaN values by extrapolated data |
---|
113 | % |
---|
114 | NON=isnan(SSTgrd); |
---|
115 | SSTgrd(NON)=SSTTMPgrd(NON); |
---|
116 | % |
---|
117 | % Write into forcing file at tindex |
---|
118 | % |
---|
119 | ncfor{'SST'}(tindex,:,:)=SSTgrd; |
---|
120 | end |
---|
121 | % |
---|
122 | close(nc) |
---|
123 | close(ncfor) |
---|
124 | !rm tmp.mat |
---|
125 | % |
---|
126 | % Plot |
---|
127 | % |
---|
128 | if makeplot == 1 |
---|
129 | tindex=1; |
---|
130 | % |
---|
131 | % Raw PATHFINDER data |
---|
132 | % |
---|
133 | nc=netcdf(pathfinder_sst_name); |
---|
134 | sst=squeeze(nc{'SST'}(tindex,jmin:jmax,imin:imax)); |
---|
135 | close(nc) |
---|
136 | sst(sst<0)=NaN; |
---|
137 | domaxis=[lonmin lonmax latmin latmax]; |
---|
138 | m_proj('mercator',... |
---|
139 | 'lon',[domaxis(1) domaxis(2)],... |
---|
140 | 'lat',[domaxis(3) domaxis(4)]); |
---|
141 | fontsize=12; |
---|
142 | m_pcolor(lon,lat,sst); |
---|
143 | shading flat |
---|
144 | caxis([min(min(sst)) max(max(sst))]) |
---|
145 | colorbar |
---|
146 | if ~isempty(coastfileplot) |
---|
147 | m_usercoast(coastfileplot,'patch',[.9 .9 .9]); |
---|
148 | end |
---|
149 | title(['Raw PATHFINDER data']) |
---|
150 | m_grid('box','fancy','tickdir','out','fontsize',fontsize); |
---|
151 | % |
---|
152 | % Data interpolated on ROMS grid |
---|
153 | % |
---|
154 | figure |
---|
155 | nc=netcdf(frcname); |
---|
156 | sstgrd=nc{'SST'}(tindex,:,:); |
---|
157 | close(nc); |
---|
158 | domaxis=[lonmin lonmax latmin latmax]; |
---|
159 | m_proj('mercator',... |
---|
160 | 'lon',[domaxis(1) domaxis(2)], ... |
---|
161 | 'lat',[domaxis(3) domaxis(4)]); |
---|
162 | m_pcolor(longrd,latgrd,sstgrd); |
---|
163 | shading flat; |
---|
164 | caxis([min(min(sst)) max(max(sst))]) |
---|
165 | colorbar; |
---|
166 | if ~isempty(coastfileplot) |
---|
167 | m_usercoast(coastfileplot,'patch',[.9 .9 .9]); |
---|
168 | end |
---|
169 | title('Data interpolated on ROMS grid') |
---|
170 | m_grid('box','fancy','tickdir','out','fontsize',fontsize); |
---|
171 | end |
---|
172 | |
---|