


Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing
file.
function write_FVCOM_z0(z0,filename,mytitle)
DESCRIPTION:
Generate a NetCDF file containing spatially variable z0 for FVCOM
INPUT
z0 = user defined roughness field (m)
roughness is defined on the elements
filename = filename to dump to
mytitle = title of the case (set as global attribute)
OUTPUT:
NetCDF file: filename
EXAMPLE USAGE
write_FVCOM_z0(z0field, 'tst_z0.nc', 'z0 tst domain')
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Pierre Cazenave (Plymouth Marine Laboratory)
Revision history
2012-06-15 Added support for native MATLAB NetCDF routines. Requires
MATLAB 2010a or higher.
==============================================================================

0001 function write_FVCOM_z0(z0,filename,mytitle) 0002 0003 % Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing 0004 % file. 0005 % 0006 % function write_FVCOM_z0(z0,filename,mytitle) 0007 % 0008 % DESCRIPTION: 0009 % Generate a NetCDF file containing spatially variable z0 for FVCOM 0010 % 0011 % INPUT 0012 % z0 = user defined roughness field (m) 0013 % roughness is defined on the elements 0014 % filename = filename to dump to 0015 % mytitle = title of the case (set as global attribute) 0016 % 0017 % OUTPUT: 0018 % NetCDF file: filename 0019 % 0020 % EXAMPLE USAGE 0021 % write_FVCOM_z0(z0field, 'tst_z0.nc', 'z0 tst domain') 0022 % 0023 % Author(s): 0024 % Geoff Cowles (University of Massachusetts Dartmouth) 0025 % Pierre Cazenave (Plymouth Marine Laboratory) 0026 % 0027 % Revision history 0028 % 2012-06-15 Added support for native MATLAB NetCDF routines. Requires 0029 % MATLAB 2010a or higher. 0030 % 0031 %============================================================================== 0032 warning off 0033 subname = 'write_FVCOM_z0'; 0034 global ftbverbose; 0035 if(ftbverbose); 0036 fprintf('\n'); fprintf(['begin : ' subname '\n']); 0037 end; 0038 0039 %------------------------------------------------------------------------------ 0040 % Parse input arguments 0041 %------------------------------------------------------------------------------ 0042 if(~exist('z0','var')) 0043 error('incorrect usage of gen_z0_file, must provide z0 field') 0044 end; 0045 if(~exist('filename','var')) 0046 error('incorrect usage of gen_z0_file, must provide filename') 0047 end; 0048 if(~exist('mytitle','var')) 0049 error('incorrect usage of gen_z0_file, must provide title field') 0050 end; 0051 0052 % check dimensions 0053 nElems = numel(z0); 0054 if(nElems == 0) 0055 error('dimension of z0 is 0, something is wrong ') 0056 end; 0057 0058 %------------------------------------------------------------------------------ 0059 % Dump to z0 NetCDF file 0060 %------------------------------------------------------------------------------ 0061 if(ftbverbose); 0062 fprintf('Dumping to z0 NetCDF file: %s\n',filename); 0063 fprintf('Size of z0 array: %i\n',nElems); 0064 end; 0065 nc = netcdf.create(filename,'clobber'); 0066 0067 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle) 0068 0069 % dimensions 0070 nele_dimid=netcdf.defDim(nc,'nele',nElems); 0071 0072 % variables and attributes 0073 z0b_varid=netcdf.defVar(nc,'z0b','NC_FLOAT',nele_dimid); 0074 netcdf.putAtt(nc,z0b_varid,'long_name','bottom roughness'); 0075 netcdf.putAtt(nc,z0b_varid,'units','m'); 0076 0077 % end definitions 0078 netcdf.endDef(nc); 0079 0080 % write data 0081 netcdf.putVar(nc,z0b_varid,z0); 0082 0083 % close file 0084 netcdf.close(nc); 0085 0086 if(ftbverbose); 0087 fprintf(['end : ' subname '\n']) 0088 end; 0089 0090