Commit e8aee693 authored by Pierre Cazenave's avatar Pierre Cazenave

Added new variable (cbcmin) to support FVCOM version 4. Also tidied up the code a bit.

parent 76aacb2c
function write_FVCOM_z0(z0,filename,mytitle)
function write_FVCOM_z0(z0,filename,mytitle,cbcmin)
% Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing
% file.
%
% function write_FVCOM_z0(z0,filename,mytitle)
% function write_FVCOM_z0(z0, filename, mytitle)
%
% DESCRIPTION:
% Generate a NetCDF file containing spatially variable z0 for FVCOM
......@@ -13,9 +12,11 @@ function write_FVCOM_z0(z0,filename,mytitle)
% roughness is defined on the elements
% filename = filename to dump to
% mytitle = title of the case (set as global attribute)
% cbcmin = minimum value of CBC (optional, defaults to 0.0018 if
% omitted).
%
% OUTPUT:
% NetCDF file: filename
% netCDF file called `filename'
%
% EXAMPLE USAGE
% write_FVCOM_z0(z0field, 'tst_z0.nc', 'z0 tst domain')
......@@ -27,65 +28,79 @@ function write_FVCOM_z0(z0,filename,mytitle)
% Revision history
% 2012-06-15 Added support for native MATLAB NetCDF routines. Requires
% MATLAB 2010a or higher.
% 2016-08-09 Added new variable (cbcmin) to support FVCOM version 4.
% Also tidied up the code a bit.
%
%==============================================================================
%warning off
subname = 'write_FVCOM_z0';
[~, subname] = fileparts(mfilename('fullpath'));
global ftbverbose;
if(ftbverbose);
fprintf('\n'); fprintf(['begin : ' subname '\n']);
end;
if ftbverbose
fprintf('\nbegin : %s\n', subname);
end
%------------------------------------------------------------------------------
% Parse input arguments
%------------------------------------------------------------------------------
if(~exist('z0','var'))
if ~exist('z0', 'var')
error('incorrect usage of write_FVCOM_z0, must provide z0 field')
end;
if(~exist('filename','var'))
end
if ~exist('filename', 'var')
error('incorrect usage of write_FVCOM_z0, must provide filename')
end;
if(~exist('mytitle','var'))
end
if ~exist('mytitle', 'var')
error('incorrect usage of write_FVCOM_z0, must provide title field')
end;
end
% check dimensions
nElems = numel(z0);
if(nElems == 0)
error('dimension of z0 is 0, something is wrong ')
end;
if nElems == 0
error('Number of elements in z0 is 0.')
end
% If we haven't been given a value of cbc min, set it to the example from
% Jianzhong Ge.
if nargin == 3
cbcmin = repmat(0.0018, nElems, 1);
end
%------------------------------------------------------------------------------
% Dump to z0 NetCDF file
% Dump to variables to the netCDF file
%------------------------------------------------------------------------------
if(ftbverbose);
fprintf('Dumping to z0 NetCDF file: %s\n',filename);
fprintf('Size of z0 array: %i\n',nElems);
end;
nc = netcdf.create(filename,'clobber');
if ftbverbose
fprintf('Dumping to z0 NetCDF file: %s\n', filename);
fprintf('Size of z0 array: %i\n', nElems);
end
nc = netcdf.create(filename, 'clobber');
netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle)
netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'title', mytitle)
netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', ...
sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
% dimensions
nele_dimid=netcdf.defDim(nc,'nele',nElems);
nele_dimid = netcdf.defDim(nc, 'nele', nElems);
% variables and attributes
z0b_varid=netcdf.defVar(nc,'z0b','NC_FLOAT',nele_dimid);
netcdf.putAtt(nc,z0b_varid,'long_name','bottom roughness');
netcdf.putAtt(nc,z0b_varid,'units','m');
z0b_varid = netcdf.defVar(nc, 'z0b', 'NC_FLOAT', nele_dimid);
netcdf.putAtt(nc, z0b_varid, 'long_name', 'bottom roughness');
netcdf.putAtt(nc, z0b_varid, 'units', 'm');
netcdf.putAtt(nc, z0b_varid, 'type', 'data');
cbcmin_varid=netcdf.defVar(nc, 'cbcmin', 'NC_FLOAT', nele_dimid);
netcdf.putAtt(nc, cbcmin_varid, 'long_name', 'bottom roughness minimum');
netcdf.putAtt(nc, cbcmin_varid, 'units', 'None');
netcdf.putAtt(nc, cbcmin_varid, 'type', 'data');
% end definitions
netcdf.endDef(nc);
% write data
netcdf.putVar(nc,z0b_varid,z0);
netcdf.putVar(nc, z0b_varid, z0);
netcdf.putVar(nc, cbcmin_varid, cbcmin);
% close file
netcdf.close(nc);
if(ftbverbose);
fprintf(['end : ' subname '\n'])
end;
if ftbverbose
fprintf('end : %s\n', subname)
end
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