Commit 7fd55120 authored by Pierre Cazenave's avatar Pierre Cazenave

Fix bug whereby the variables which do not require interpolation were not...

Fix bug whereby the variables which do not require interpolation were not being correctly transferred
parent 3199d9a5
...@@ -2,11 +2,11 @@ function fvcom = grid2fvcom(Mobj,vars,data) ...@@ -2,11 +2,11 @@ function fvcom = grid2fvcom(Mobj,vars,data)
% Interpolate regularly gridded wind speed data onto a given FVCOM grid % Interpolate regularly gridded wind speed data onto a given FVCOM grid
% %
% grid2fvcom(Mobj,vars,wind,fvcom_forcing_file,infos) % grid2fvcom(Mobj,vars,wind,fvcom_forcing_file,infos)
% %
% DESCRIPTION: % DESCRIPTION:
% Takes a given NCEP reanalysis grid file and interpolates the U10 and % Takes a given NCEP reanalysis grid file and interpolates the U10 and
% V10 values onto the specified FVCOM grid file. % V10 values onto the specified FVCOM grid file.
% %
% INPUT: % INPUT:
% Mobj - MATLAB mesh object % Mobj - MATLAB mesh object
% vars - a cell array of the variables to be interpolated on the FVCOM % vars - a cell array of the variables to be interpolated on the FVCOM
...@@ -16,35 +16,35 @@ function fvcom = grid2fvcom(Mobj,vars,data) ...@@ -16,35 +16,35 @@ function fvcom = grid2fvcom(Mobj,vars,data)
% y - y data (probably best in cartesian for the interpolation) % y - y data (probably best in cartesian for the interpolation)
% The struct must also contain all the variables defined in vars. % The struct must also contain all the variables defined in vars.
% time - time vector (in Modified Julian Days) % time - time vector (in Modified Julian Days)
% %
% OUTPUT: % OUTPUT:
% fvcom - struct of the interpolated data values at the model nodes and % fvcom - struct of the interpolated data values at the model nodes and
% element centres. Also includes any variables which were in the input % element centres. Also includes any variables which were in the input
% struct but which have not been interpolated (e.g. time). % struct but which have not been interpolated (e.g. time).
% %
% NOTE: % NOTE:
% The shape of the returned arrays for rhum and slp (via % The shape of the returned arrays for rhum and slp (via
% get_NCEP_forcing.m) have sometimes differed from the other vairables % get_NCEP_forcing.m) have sometimes differed from the other vairables
% (they appear to be projected onto a different grid). Unless you % (they appear to be projected onto a different grid). Unless you
% desperately need them, I would suggest omitting them from the % desperately need them, I would suggest omitting them from the
% interpolation here as this assumes the arrays are all the same size. % interpolation here as this assumes the arrays are all the same size.
% %
% Author(s): % Author(s):
% Pierre Cazenave (Plymouth Marine Laboratory) % Pierre Cazenave (Plymouth Marine Laboratory)
% %
% Revision history: % Revision history:
% 2012-10-15 First version based on ncep2fvcom_U10V10.m in the % 2012-10-15 First version based on ncep2fvcom_U10V10.m in the
% fvcom-toolbox. % fvcom-toolbox.
% 2012-10-16 Removed the code to read the NCEP file. Instead, farmed that % 2012-10-16 Removed the code to read the NCEP file. Instead, farmed that
% out to a new function (read_NCEP_wind) so that the relevant section can % out to a new function (read_NCEP_wind) so that the relevant section can
% be more readily extracted (rather than using the entire globe's data: % be more readily extracted (rather than using the entire globe's data:
% it's easier to subsample and provide the subsampled data here). % it's easier to subsample and provide the subsampled data here).
% 2012-10-17 Add outputs to the function for use in visualisation. % 2012-10-17 Add outputs to the function for use in visualisation.
% 2012-10-19 Add wind struct as input rather than separate u, v, time and % 2012-10-19 Add wind struct as input rather than separate u, v, time and
% lat/long arrays. Makes invocation a bit cleaner. % lat/long arrays. Makes invocation a bit cleaner.
% 2012-11-01 Farmed out the creation of the NetCDF file to % 2012-11-01 Farmed out the creation of the NetCDF file to
% write_FVCOM_forcing.m and made this purely an interpolation script. % write_FVCOM_forcing.m and made this purely an interpolation script.
% %
%========================================================================== %==========================================================================
warning off warning off
...@@ -89,11 +89,11 @@ end ...@@ -89,11 +89,11 @@ end
for vv=1:length(vars) for vv=1:length(vars)
if strcmpi(vars{vv}, 'time') if strcmpi(vars{vv}, 'time')
fprintf('transferring variable %s as is\n', vars{vv}) fprintf('transferring variable %s as is\n', vars{vv})
fvcom.(vars{vv}) = data.(vars{1}); fvcom.(vars{vv}) = data.(vars{vv});
continue continue
elseif strcmpi(vars{vv}, 'lat') || strcmpi(vars{vv}, 'lon') || strcmpi(vars{vv}, 'x') || strcmpi(vars{vv}, 'y') elseif strcmpi(vars{vv}, 'lat') || strcmpi(vars{vv}, 'lon') || strcmpi(vars{vv}, 'x') || strcmpi(vars{vv}, 'y')
fprintf('reassigning variable %s from unstructured grid\n', vars{vv}) fprintf('reassigning variable %s from unstructured grid\n', vars{vv})
fvcom.(vars{vv}) = Mobj.(vars{1}); fvcom.(vars{vv}) = Mobj.(vars{vv});
else else
% Preallocate the output arrays % Preallocate the output arrays
fvcom.(vars{vv}).data = zeros(nElems,ntimes); fvcom.(vars{vv}).data = zeros(nElems,ntimes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment