Home > fvcom_prepro > write_FVCOM_probes.m

write_FVCOM_probes

PURPOSE ^

Write a namelist for the timeseries extraction at specifc nodes.

SYNOPSIS ^

function write_FVCOM_probes(nml_file, interval, probes)

DESCRIPTION ^

 Write a namelist for the timeseries extraction at specifc nodes.

 write_FVCOM_probes(Mobj, nml_file, interval, varlist, locations)

 DESCRIPTION:
   Write a namelist of variables to extract at given positions with the
   interval specified.

 INPUT:
   nml_file - full path to the output namelist file.
   interval - output interval (in seconds)
   probe - struct of structs with fields whose names are the probe title.
   Each probe struct must have the following fields:
       node        - unstructured grid node ID (for all scalars except u
           and v).
       elem        - unstructured grid element ID (for u and v only).
       file        - file name for the current probe's output. If the
           'variable' field is a cell array of multiple variables, each
           output file name will have the variable name appended (e.g.
           'Newlyn.dat' becomes 'Newlyn_el.dat' for elevation time
           series).
       description - description of this output. If multiple variable are
           specified in variable, the length of the description must match
           the number of variables.
       variable    - variable name to extract from FVCOM. Define as a cell
           array for multiple variables. Output file names in the namelist
           will be appended with the variable name. Variable names are the
           internal FVCOM variable names (which is not always the same as
           the output file variable name). Check mod_probe.F in subroutine
           PROBE_STORE for the full list of supported variables. I've
           reproduced that list in the NOTES below.
       longname    - long name for the current variable. Must also match
           the number of variables.
       levels      - start and end level for 3D variables (u, v, w, ww,
           t1, s1, q2, l, q2l, km, kh, kq, rho1).

 OUTPUT:
   Namelist for inclusion in the main FVCOM namelist (PROBES_FILE).

 EXAMPLE USAGE:
   probes.newlyn.file = 'newlyn_elev.dat';
   probes.newlyn.node = 1045;
   probes.newlyn.elem = 467;
   probes.newlyn.description = 'Elevation at Newlyn';
   probes.newlyn.variable = 'el';
   probes.newlyn.longname = 'Surface elevation (m)';
   probes.newlyn.levels = [1, length(Mobj.siglay)];
   write_FVCOM_river_nml(Mobj, 'casename_probes.nml', 600, probes)

 NOTES:
   Available output variables are currently (FVCOM v3.1.6) limited to:
       - el - surface elevation
       - t1, s1 - temperature and salinity
       - rho1 - density
       - u, v, ua, va - velocity and depth-averaged velocities
       - ww - vertical water velocity
       - w - vertical velocity in sigma system
       - q2, l, q2l - turbulent kinetic energy (TKE), TKE lengthscale and
           TKE times TKE lengthscale
       - km, kh, kq - turbulent eddy viscosity for momentum, scalars and
           q2/q2l
       - aice, vice, uice2, vice2 - ice parameters
       - csed - suspended sediment concentration

 Author(s):
   Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history:
   2014-02-10 - First version.
   2015-01-14 - Fix export of the u and v locations to use the closest
   element instead of the node ID. Using the node ID for the u and v data
   will yield velocity time series miles away from the actual location of
   interest.

==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function write_FVCOM_probes(nml_file, interval, probes)
0002 % Write a namelist for the timeseries extraction at specifc nodes.
0003 %
0004 % write_FVCOM_probes(Mobj, nml_file, interval, varlist, locations)
0005 %
0006 % DESCRIPTION:
0007 %   Write a namelist of variables to extract at given positions with the
0008 %   interval specified.
0009 %
0010 % INPUT:
0011 %   nml_file - full path to the output namelist file.
0012 %   interval - output interval (in seconds)
0013 %   probe - struct of structs with fields whose names are the probe title.
0014 %   Each probe struct must have the following fields:
0015 %       node        - unstructured grid node ID (for all scalars except u
0016 %           and v).
0017 %       elem        - unstructured grid element ID (for u and v only).
0018 %       file        - file name for the current probe's output. If the
0019 %           'variable' field is a cell array of multiple variables, each
0020 %           output file name will have the variable name appended (e.g.
0021 %           'Newlyn.dat' becomes 'Newlyn_el.dat' for elevation time
0022 %           series).
0023 %       description - description of this output. If multiple variable are
0024 %           specified in variable, the length of the description must match
0025 %           the number of variables.
0026 %       variable    - variable name to extract from FVCOM. Define as a cell
0027 %           array for multiple variables. Output file names in the namelist
0028 %           will be appended with the variable name. Variable names are the
0029 %           internal FVCOM variable names (which is not always the same as
0030 %           the output file variable name). Check mod_probe.F in subroutine
0031 %           PROBE_STORE for the full list of supported variables. I've
0032 %           reproduced that list in the NOTES below.
0033 %       longname    - long name for the current variable. Must also match
0034 %           the number of variables.
0035 %       levels      - start and end level for 3D variables (u, v, w, ww,
0036 %           t1, s1, q2, l, q2l, km, kh, kq, rho1).
0037 %
0038 % OUTPUT:
0039 %   Namelist for inclusion in the main FVCOM namelist (PROBES_FILE).
0040 %
0041 % EXAMPLE USAGE:
0042 %   probes.newlyn.file = 'newlyn_elev.dat';
0043 %   probes.newlyn.node = 1045;
0044 %   probes.newlyn.elem = 467;
0045 %   probes.newlyn.description = 'Elevation at Newlyn';
0046 %   probes.newlyn.variable = 'el';
0047 %   probes.newlyn.longname = 'Surface elevation (m)';
0048 %   probes.newlyn.levels = [1, length(Mobj.siglay)];
0049 %   write_FVCOM_river_nml(Mobj, 'casename_probes.nml', 600, probes)
0050 %
0051 % NOTES:
0052 %   Available output variables are currently (FVCOM v3.1.6) limited to:
0053 %       - el - surface elevation
0054 %       - t1, s1 - temperature and salinity
0055 %       - rho1 - density
0056 %       - u, v, ua, va - velocity and depth-averaged velocities
0057 %       - ww - vertical water velocity
0058 %       - w - vertical velocity in sigma system
0059 %       - q2, l, q2l - turbulent kinetic energy (TKE), TKE lengthscale and
0060 %           TKE times TKE lengthscale
0061 %       - km, kh, kq - turbulent eddy viscosity for momentum, scalars and
0062 %           q2/q2l
0063 %       - aice, vice, uice2, vice2 - ice parameters
0064 %       - csed - suspended sediment concentration
0065 %
0066 % Author(s):
0067 %   Pierre Cazenave (Plymouth Marine Laboratory)
0068 %
0069 % Revision history:
0070 %   2014-02-10 - First version.
0071 %   2015-01-14 - Fix export of the u and v locations to use the closest
0072 %   element instead of the node ID. Using the node ID for the u and v data
0073 %   will yield velocity time series miles away from the actual location of
0074 %   interest.
0075 %
0076 %==========================================================================
0077 
0078 subname = 'write_FVCOM_probes';
0079 
0080 global ftbverbose;
0081 if ftbverbose
0082     fprintf('\nbegin : %s\n', subname)
0083 end
0084 
0085 fnames = fieldnames(probes);
0086 np = length(fnames);
0087 
0088 f = fopen(nml_file, 'w');
0089 assert(f >= 0, 'Error writing to %s. Check permissions and try again.', nml_file)
0090 
0091 for p = 1:np
0092     if iscell(probes.(fnames{p}).variable)
0093         nv = length(probes.(fnames{p}).variable);
0094         assert(length(probes.(fnames{p}).description) == nv, 'Specify one description per output variable.')
0095         assert(length(probes.(fnames{p}).description) == nv, 'Specify one longname per output variable.')
0096     else
0097         nv = 1;
0098         vname = probes.(fnames{p}).variable;
0099         lname = probes.(fnames{p}).longname;
0100         desc = probes.(fnames{p}).description;
0101     end
0102     for v = 1:nv
0103         if nv > 1
0104             vname = probes.(fnames{p}).variable{v};
0105             lname = probes.(fnames{p}).longname{v};
0106             desc = probes.(fnames{p}).description{v};
0107         end
0108         [pathstr, name, ext] = fileparts(probes.(fnames{p}).file);
0109         name = sprintf('%s_%s%s', name, vname, ext);
0110         file = fullfile(pathstr, name);
0111         fprintf(f, '&NML_PROBE\n');
0112         fprintf(f, ' PROBE_INTERVAL = "seconds=%.1f",\n', interval);
0113         if any(strcmpi(vname, {'u', 'v'}))
0114             fprintf(f, ' PROBE_LOCATION = %i,\n', probes.(fnames{p}).elem);
0115         else
0116             fprintf(f, ' PROBE_LOCATION = %i,\n', probes.(fnames{p}).node);
0117         end
0118         fprintf(f, ' PROBE_TITLE = "%s",\n', file);
0119         % If we've got something which is vertically resolved, output the
0120         % vertical levels.
0121         switch vname
0122             case {'u', 'v', 'w', 'ww', 't1', 's1', 'km', 'kh', 'q2', 'l', 'q2l', 'kq', 'rho1'}
0123                 fprintf(f, ' PROBE_LEVELS = %i %i,\n', probes.(fnames{p}).levels);
0124         end
0125         fprintf(f, ' PROBE_DESCRIPTION = "%s",\n', desc);
0126         fprintf(f, ' PROBE_VARIABLE = "%s",\n', vname);
0127         fprintf(f, ' PROBE_VAR_NAME = "%s"\n', lname);
0128         fprintf(f, '/\n');
0129     end
0130 end
0131 
0132 fclose(f);
0133 
0134 if ftbverbose
0135     fprintf('end   : %s\n', subname)
0136 end

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005