


Write spatially-variable flag (bedflag) to FVCOM forcing file
function write_FVCOM_bedflag(bedflag,filename,mytitle)
DESCRIPTION:
Generate a netCDF file containing spatially variable bedflag for FVCOM
INPUT
bedflag = user defined bed flag (=0, no erosion/bedosition, =1, erosion/bedosition)
on the nodes
filename = filename to dump to
mytitle = title of the case (set as global attribute)
OUTPUT:
netCDF file: filename
EXAMPLE USAGE
write_FVCOM_bedflag(bedflag, 'tst_bedflag.nc', 'no bedosition/erosion in Skagit river')
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Pierre Cazenave (Plymouth Marine Laboratory)
Revision history
2016-02-18 Updated the code to use the MATLAB netCDF routines.
2017-03-23 Add the supplied title to the generated netCDF file.
2017-03-29 Write the flag as a float as FVCOM expects.
==========================================================================

0001 function write_FVCOM_bedflag(bedflag,filename,mytitle) 0002 % Write spatially-variable flag (bedflag) to FVCOM forcing file 0003 % 0004 % function write_FVCOM_bedflag(bedflag,filename,mytitle) 0005 % 0006 % DESCRIPTION: 0007 % Generate a netCDF file containing spatially variable bedflag for FVCOM 0008 % 0009 % INPUT 0010 % bedflag = user defined bed flag (=0, no erosion/bedosition, =1, erosion/bedosition) 0011 % on the nodes 0012 % filename = filename to dump to 0013 % mytitle = title of the case (set as global attribute) 0014 % 0015 % OUTPUT: 0016 % netCDF file: filename 0017 % 0018 % EXAMPLE USAGE 0019 % write_FVCOM_bedflag(bedflag, 'tst_bedflag.nc', 'no bedosition/erosion in Skagit river') 0020 % 0021 % Author(s): 0022 % Geoff Cowles (University of Massachusetts Dartmouth) 0023 % Pierre Cazenave (Plymouth Marine Laboratory) 0024 % 0025 % Revision history 0026 % 2016-02-18 Updated the code to use the MATLAB netCDF routines. 0027 % 2017-03-23 Add the supplied title to the generated netCDF file. 0028 % 2017-03-29 Write the flag as a float as FVCOM expects. 0029 % 0030 %========================================================================== 0031 0032 global ftbverbose 0033 [~, subname] = fileparts(mfilename('fullpath')); 0034 if ftbverbose 0035 fprintf('\nbegin : %s\n', subname) 0036 end 0037 0038 %-------------------------------------------------------------------------- 0039 % Parse input arguments 0040 %-------------------------------------------------------------------------- 0041 if ~exist('bedflag', 'var') 0042 error('incorrect usage of gen_bedflag_file, must provide bedflag field') 0043 end 0044 if ~exist('filename', 'var') 0045 error('incorrect usage of gen_bedflag_file, must provide filename') 0046 end 0047 if ~exist('mytitle', 'var') 0048 error('incorrect usage of gen_bedflag_file, must provide title field') 0049 end 0050 0051 % check dimensions 0052 nVerts = numel(bedflag); 0053 if(nVerts == 0) 0054 error('dimension of bedflag is 0, something is wrong ') 0055 end; 0056 0057 %-------------------------------------------------------------------------- 0058 % Dump to bedflag netCDF file 0059 %-------------------------------------------------------------------------- 0060 if ftbverbose 0061 fprintf('Dumping to bedflag netCDF file: %s\n', filename); 0062 fprintf('Size of bedflag array: %d\n', nVerts); 0063 end 0064 0065 nc = netcdf.create(filename, 'clobber'); 0066 0067 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'title', mytitle) 0068 0069 0070 % define dimensions 0071 node_dimid=netcdf.defDim(nc, 'node', numel(bedflag)); 0072 0073 % define variables and attributes 0074 node_varid=netcdf.defVar(nc, 'bedflag', 'NC_FLOAT', node_dimid); 0075 netcdf.putAtt(nc,node_varid, 'long_name', 'bed deposition flag'); 0076 netcdf.putAtt(nc,node_varid, 'units', '-'); 0077 0078 % end definitions 0079 netcdf.endDef(nc); 0080 0081 % dump data 0082 netcdf.putVar(nc, node_varid, bedflag); 0083 0084 % close netCDF 0085 netcdf.close(nc) 0086 0087 if ftbverbose 0088 fprintf('end : %s\n', subname) 0089 end