


Write a namelist for the river nodes.
write_FVCOM_river_nml(Mobj, nml_file, nc_file, vString))
DESCRIPTION:
Using the output of get_POLCOMS_rivers in Mobj, output the river name,
input file, grid node and vertical distribution into a namelist (.nml
file).
NOTE: if the vertical distribution is uniform, the string 'uniform'
will be output. If a non-uniform distribution is detected, then the
name list will need to be edited to reflect the distribution specified
in the sigma.dat file.
INPUT:
Mobj - MATLAB mesh object with the river data.
nml_file - full path to the output namelist file.
nc_file - full path to the NetCDF file containing the river data.
vString - optional, pass a string (e.g. 'uniform') to write as the
RIVER_VERTICAL_DISTRIBUTION in the namelist, bypassing the automated
string generation.
Alternative vString can be an array of fractional distribution (one per depth)
for r = 1:length(Mobj2.river_nodes)
Z1=Mobj2.siglevz(Mobj2.river_nodes(r),1:end-1);
Z2=Mobj2.siglevz(Mobj2.river_nodes(r),2:end);
RivDist(r,:)=(exp(Z1/5)-exp(Z2/5));
end
OUTPUT:
Namelist for inclusion in the main FVCOM namelist (RIVER_INFO_FILE).
EXAMPLE USAGE:
write_FVCOM_river_nml(Mobj, 'casename_river.nml', 'casename_river.nc', RivDist)
Author(s):
Pierre Cazenave (Plymouth Marine Laboratory)
Ricardo Torres (Plymouth Marine Laboratory)
Revision history:
2013-03-21 - First version.
2013-08-16 - Add optional fourth argument of a string to supply as the
RIVER_VERTICAL_DISTRIBUTION (e.g. 'uniform').
2013-10-16 - Fix the handling of the optional vString argument.
2018-03-28 - (RJT) Added the option of outputing float vertical
distribution for river flows not just uniform for all rivers.
2018-05-08 - Fixed vertical distribution handling to support both the
original functionality and the new float distribution.
==========================================================================

0001 function write_FVCOM_river_nml(Mobj, nml_file, nc_file, vString) 0002 % Write a namelist for the river nodes. 0003 % 0004 % write_FVCOM_river_nml(Mobj, nml_file, nc_file, vString)) 0005 % 0006 % DESCRIPTION: 0007 % Using the output of get_POLCOMS_rivers in Mobj, output the river name, 0008 % input file, grid node and vertical distribution into a namelist (.nml 0009 % file). 0010 % 0011 % NOTE: if the vertical distribution is uniform, the string 'uniform' 0012 % will be output. If a non-uniform distribution is detected, then the 0013 % name list will need to be edited to reflect the distribution specified 0014 % in the sigma.dat file. 0015 % 0016 % INPUT: 0017 % Mobj - MATLAB mesh object with the river data. 0018 % nml_file - full path to the output namelist file. 0019 % nc_file - full path to the NetCDF file containing the river data. 0020 % vString - optional, pass a string (e.g. 'uniform') to write as the 0021 % RIVER_VERTICAL_DISTRIBUTION in the namelist, bypassing the automated 0022 % string generation. 0023 % Alternative vString can be an array of fractional distribution (one per depth) 0024 % for r = 1:length(Mobj2.river_nodes) 0025 % Z1=Mobj2.siglevz(Mobj2.river_nodes(r),1:end-1); 0026 % Z2=Mobj2.siglevz(Mobj2.river_nodes(r),2:end); 0027 % RivDist(r,:)=(exp(Z1/5)-exp(Z2/5)); 0028 % end 0029 % 0030 % OUTPUT: 0031 % Namelist for inclusion in the main FVCOM namelist (RIVER_INFO_FILE). 0032 % 0033 % EXAMPLE USAGE: 0034 % write_FVCOM_river_nml(Mobj, 'casename_river.nml', 'casename_river.nc', RivDist) 0035 % 0036 % Author(s): 0037 % Pierre Cazenave (Plymouth Marine Laboratory) 0038 % Ricardo Torres (Plymouth Marine Laboratory) 0039 % 0040 % Revision history: 0041 % 2013-03-21 - First version. 0042 % 2013-08-16 - Add optional fourth argument of a string to supply as the 0043 % RIVER_VERTICAL_DISTRIBUTION (e.g. 'uniform'). 0044 % 2013-10-16 - Fix the handling of the optional vString argument. 0045 % 2018-03-28 - (RJT) Added the option of outputing float vertical 0046 % distribution for river flows not just uniform for all rivers. 0047 % 2018-05-08 - Fixed vertical distribution handling to support both the 0048 % original functionality and the new float distribution. 0049 %========================================================================== 0050 0051 subname = 'write_FVCOM_river_nml'; 0052 0053 global ftbverbose; 0054 if ftbverbose 0055 fprintf('\nbegin : %s\n', subname) 0056 end 0057 0058 nr = length(Mobj.river_nodes); 0059 0060 f = fopen(nml_file, 'w'); 0061 assert(f >= 0, 'Error writing to %s. Check permissions and try again.', nml_file) 0062 0063 for r = 1:nr 0064 fprintf(f, ' &NML_RIVER\n'); 0065 fprintf(f, ' RIVER_NAME = ''%s'',\n', Mobj.river_names{r}); 0066 fprintf(f, ' RIVER_FILE = ''%s'',\n', nc_file); 0067 fprintf(f, ' RIVER_GRID_LOCATION = %d,\n', Mobj.river_nodes(r)); 0068 0069 % Build the vertical distribution string. Round to 15 decimal places so 0070 % the unique check works (hopefully no one needs that many vertical 0071 % layers...). 0072 vDist = roundn(abs(diff(Mobj.siglev)), -15); 0073 if length(unique(vDist)) == 1 || ~exist(vString, 'var') 0074 vString = '''uniform'''; 0075 elseif nargin <= 3 0076 vString = char(); 0077 % loop through each river as they can have different distributions 0078 if ndim(vDist)==1 % only one fixed distribution 0079 for ii = 1:size(vDist) 0080 vString = [vString, sprintf('%f ', vDist(ii))]; 0081 end 0082 end 0083 else % we have different vDist for each river 0084 vString = char(); 0085 for ii = 1:size(vString,2) 0086 vString = [vString2, sprintf('%1.5f ', vString(r,ii))]; 0087 end 0088 end 0089 % Output whatever vertical distribution string we've got to the 0090 % namelist file. 0091 fprintf(f, ' RIVER_VERTICAL_DISTRIBUTION = %s\n', vString); 0092 fprintf(f, ' /\n'); 0093 end 0094 0095 fclose(f); 0096 0097 if ftbverbose 0098 fprintf('end : %s\n', subname) 0099 end