


Script to create the model run namelist.
res = write_model_nml(conf, nml, fmt)
INPUT
conf - struct with the following fields:
fvcom_model: directory into which the namelist should be written.
casename: casename to use in the file name.
nml - namelist inputs struct generated by make_default_nml.
fmt - number format struct generated by make_default_nml.
OUTPUT
Model run namelist file.
Author(s)
Ricardo Torres (Plymouth Marine Laboratory)
Pierre Cazenave (Plymouth Marine Laboratory)
Revision history
2017-01-12 First version.
2017-02-03 Fix output directory variable use.
2017-08-01 Remove tabs from the namelists.

0001 function res = write_model_nml(conf, nml, fmt) 0002 % Script to create the model run namelist. 0003 % 0004 % res = write_model_nml(conf, nml, fmt) 0005 % 0006 % INPUT 0007 % conf - struct with the following fields: 0008 % fvcom_model: directory into which the namelist should be written. 0009 % casename: casename to use in the file name. 0010 % nml - namelist inputs struct generated by make_default_nml. 0011 % fmt - number format struct generated by make_default_nml. 0012 % OUTPUT 0013 % Model run namelist file. 0014 % 0015 % Author(s) 0016 % Ricardo Torres (Plymouth Marine Laboratory) 0017 % Pierre Cazenave (Plymouth Marine Laboratory) 0018 % 0019 % Revision history 0020 % 2017-01-12 First version. 0021 % 2017-02-03 Fix output directory variable use. 0022 % 2017-08-01 Remove tabs from the namelists. 0023 0024 if ~( exist(conf.fvcom_model, 'dir') ) 0025 mkdir(conf.fvcom_model); 0026 end 0027 if isfield(conf,'casename_out') 0028 fname = fullfile(conf.fvcom_model, [conf.casename_out, '.nml']); 0029 else 0030 fname = fullfile(conf.fvcom_model, [conf.casename, '.nml']); 0031 end 0032 fnml = fopen(fname, 'wt'); 0033 0034 nml_blocks = fieldnames(nml); 0035 for nn = 1:length(nml_blocks) 0036 line = [' &', nml_blocks{nn}]; 0037 fprintf(fnml, '%s\n', line); 0038 clear line 0039 nml_vars = fieldnames(nml.(nml_blocks{nn})); 0040 for vv = 1:length(nml_vars) 0041 var_value = nml.(nml_blocks{nn}).(nml_vars{vv}); 0042 if ischar(var_value) 0043 if any(strcmp(var_value, {'T','F'})) 0044 formatstr = ' %s = %s'; 0045 0046 else 0047 formatstr=[' %s = ', '''', '%s', '''']; 0048 end 0049 else 0050 formatstr= [' %s = ', repmat([fmt.(nml_blocks{nn}).(nml_vars{vv}).format, ','], 1, length(var_value))]; 0051 end 0052 line = sprintf(formatstr, nml_vars{vv}, var_value); 0053 fprintf(fnml, '%s\n', line); 0054 clear line 0055 end 0056 fprintf(fnml, ' /\n'); 0057 fprintf(fnml, '\n'); 0058 end 0059 res = fclose(fnml); 0060 return