source: Roms_tools/Preprocessing_tools/pathfinder_sst.m @ 1

Last change on this file since 1 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 4.5 KB
Line 
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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35close all
36clear all
37%%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%
38%
39romstools_param
40%
41Roa=1e8;    % extrapolation decay length scale
42default=0;
43icoarse=8; % resolution coef for coarse grid
44spval=NaN;  % Missing value
45%
46%%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
47%
48% Read ROMS Grid
49%
50ncgrd=netcdf(grdname);
51latgrd=ncgrd{'lat_rho'}(:);  % model grid
52longrd=ncgrd{'lon_rho'}(:);
53maskgrd=ncgrd{'mask_rho'}(:);
54maskgrd(maskgrd==0)=NaN;
55close(ncgrd)
56lonmin=min(min(longrd))-1;
57lonmax=max(max(longrd))+1;
58latmin=min(min(latgrd))-1;
59latmax=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%
66nc=netcdf(pathfinder_sst_name);
67LON=nc{'X'}(:);
68LAT=nc{'Y'}(:);
69imin=max(find(LON<lonmin));
70imax=min(find(LON>lonmax));
71jmin=max(find(LAT<latmin));
72jmax=min(find(LAT>latmax));
73LON=LON(imin:imax);
74LAT=LAT(jmin:jmax);
75[lon,lat]=meshgrid(LON,LAT);
76%
77% Create coarser grid for land extrapolation
78%
79LONTMP=LON(1:icoarse:end);
80LATTMP=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%
86ncfor=netcdf(frcname,'write');
87for 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;
120end
121%
122close(nc)
123close(ncfor)
124!rm tmp.mat
125%
126% Plot
127%
128if 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);
171end
172 
Note: See TracBrowser for help on using the repository browser.