Home > fvcom_prepro > write_FVCOM_meanflow_ascii.m

write_FVCOM_meanflow_ascii

PURPOSE ^

Export mean flow forcing files hard-coded into mod_obcs2.F.

SYNOPSIS ^

function write_FVCOM_meanflow_ascii(Mobj, casename)

DESCRIPTION ^

 Export mean flow forcing files hard-coded into mod_obcs2.F.

 function write_FVCOM_meanflow_ascii(Mobj, datfile, data)

 DESCRIPTION:
    Setup an FVCOM hydrographic open boundary mean flow forcing file.

 INPUT:
   Mobj     - MATLAB mesh object (with fields mf_time, siglay, siglev,
               nObcNodes and read_obc_nodes).
            - Also requires two fields called meanflow_u and meanflow_v
               which are arrays of u and v of sizes (nObcElements,
               length(siglay), length(mf_times)).
   casename - Output file prefix. Output files will be
               /path/to/casename_suffix.dat, where suffix is one of:
                   - meanflow
                   - tide_cell
                   - tide_node
                   - tide_el
                   - tide_uv
   data     - 2D array of mean flow along the open boundary (nobc, time).

 OUTPUT:
    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
    named ncfile.

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

 Revision history
    2013-02-25 - First version.
 
 TODO: Implement support for multiple open boundaries in all the outputs.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function write_FVCOM_meanflow_ascii(Mobj, casename)
0002 % Export mean flow forcing files hard-coded into mod_obcs2.F.
0003 %
0004 % function write_FVCOM_meanflow_ascii(Mobj, datfile, data)
0005 %
0006 % DESCRIPTION:
0007 %    Setup an FVCOM hydrographic open boundary mean flow forcing file.
0008 %
0009 % INPUT:
0010 %   Mobj     - MATLAB mesh object (with fields mf_time, siglay, siglev,
0011 %               nObcNodes and read_obc_nodes).
0012 %            - Also requires two fields called meanflow_u and meanflow_v
0013 %               which are arrays of u and v of sizes (nObcElements,
0014 %               length(siglay), length(mf_times)).
0015 %   casename - Output file prefix. Output files will be
0016 %               /path/to/casename_suffix.dat, where suffix is one of:
0017 %                   - meanflow
0018 %                   - tide_cell
0019 %                   - tide_node
0020 %                   - tide_el
0021 %                   - tide_uv
0022 %   data     - 2D array of mean flow along the open boundary (nobc, time).
0023 %
0024 % OUTPUT:
0025 %    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
0026 %    named ncfile.
0027 %
0028 % Author(s):
0029 %    Pierre Cazenave (Plymouth Marine Laboratory)
0030 %
0031 % Revision history
0032 %    2013-02-25 - First version.
0033 %
0034 % TODO: Implement support for multiple open boundaries in all the outputs.
0035 %
0036 %==========================================================================
0037 
0038 subname = 'write_FVCOM_meanflow_ascii';
0039 
0040 global ftbverbose
0041 if ftbverbose
0042     fprintf(['\nbegin : ' subname '\n'])
0043 end
0044 
0045 %% _meanflow.dat -- mean flow velocities at the open boundary elements (?).
0046 
0047 % Create depth averaged velocity from the 3D velocity data in Mobj.
0048 velocity = squeeze(mean(sqrt(Mobj.meanflow_u.^2 + Mobj.meanflow_v.^2), 2));
0049 
0050 f = fopen([casename, '_meanflow.dat'], 'w');
0051 if f < 0
0052     error('Problem writing to _meanflow.dat file. Check permissions and try again.')
0053 end
0054 % Number of boundary nodes
0055 fprintf(f, '%8d\n', Mobj.nObcNodes);
0056 % Boundary node IDs
0057 for i = 1:Mobj.nObcNodes
0058     fprintf(f, '%8d\n', Mobj.read_obc_nodes{1}(i));
0059 end
0060 % Sigma level distribution
0061 s = '%8d';
0062 for ss = 1:length(Mobj.siglay)
0063     if ss < length(Mobj.siglay)
0064         s = [s, '%8.4f'];
0065     else
0066         s = [s, '%8.4f\n'];
0067     end
0068 end
0069 for i = 1:numel(Mobj.read_obc_nodes{1})
0070     fprintf(f, s, [i, abs(diff(Mobj.siglev))]);
0071 end
0072 
0073 % Number of times and boundary points
0074 [nb, nt] = size(velocity);
0075 
0076 % Add the number of time steps
0077 fprintf(f, '%i\n', nt);
0078 
0079 s = '%8.4f\n';
0080 for ss = 1:nb
0081     if ss < nb
0082         s = [s, '%8.4f'];
0083     else
0084         s = [s, '%8.4f\n'];
0085     end
0086 end
0087 for i = 1:size(velocity, 2)
0088     fprintf(f, s, [i - 1, velocity(:, i)']);
0089 end
0090 
0091 fclose(f);
0092 
0093 %% _tide_node.dat -- nodes along the open boundaries.
0094 f = fopen([casename, '_tide_node.dat'], 'w');
0095 if f < 0
0096     error('Problem writing to _tide_node.dat file. Check permissions and try again.')
0097 end
0098 % Boundary node IDs
0099 
0100 % Get a list of the open boundary nodes. Transpose Mobj.obc_nodes so the
0101 % order of the boundary nodes is preserved.
0102 tmpObcNodes = Mobj.obc_nodes';
0103 % Flip it back so it's the same shape as it would have been using the old
0104 % code.
0105 ObcNodes = tmpObcNodes(tmpObcNodes ~= 0)';
0106 
0107 fprintf(f, '%8d\n', numel(ObcNodes));
0108 for i = 1:numel(ObcNodes(i))
0109     fprintf(f, '%8i\n', ObcNodes(i));
0110 end
0111 
0112 fclose(f);
0113 
0114 %% _tide_cell.dat -- elements which have two nodes on an open boundary.
0115 f = fopen([casename, '_tide_cell.dat'], 'w');
0116 if f < 0
0117     error('Problem writing to _tide_cell.dat file. Check permissions and try again.')
0118 end
0119 if ~isfield(Mobj, 'read_obc_elements')
0120     error('Missing list of boundary element IDs. Run find_boundary_elements and try again.')
0121 end
0122 % Boundary element IDs
0123 ne = Mobj.nObcElements;
0124 fprintf(f, '%8d\n', ne);
0125 for j = 1:Mobj.nObs; % number of open boundaries
0126     for i = 1:numel(Mobj.read_obc_elements{j})
0127         fprintf(f, '%8i\n', Mobj.read_obc_elements{j}(i));
0128     end
0129 end
0130 
0131 fclose(f);
0132 
0133 %% _tide_el.dat -- surface elevations with time.
0134 f = fopen([casename, '_tide_el.dat'], 'w');
0135 if f < 0
0136     error('Problem writing to _tide_el.dat file. Check permissions and try again.')
0137 end
0138 % Boundary node IDs
0139 if ~isfield(Mobj, 'surfaceElevation')
0140     error('Missing predicted surface elevation necessary for mean flow.')
0141 end
0142 if ~isfield(Mobj, 'el_time')
0143     error('Missing predicted surface elevation time series necessary for mean flow.')
0144 end
0145 
0146 [nb, nt] = size(Mobj.surfaceElevation);
0147 
0148 s = '%8d';
0149 for ss = 1:nb
0150     if ss < nb
0151         s = [s, '%8.4f'];
0152     else
0153         s = [s, '%8.4f\n'];
0154     end
0155 end
0156 
0157 for i = 1:nt
0158     fprintf(f, s', [round(Mobj.el_time(i)), Mobj.surfaceElevation(:, i)']);
0159 end
0160 
0161 fclose(f);
0162 
0163 %% _tide_uv.dat -- boundary velocities
0164 % The format here is pretty funky. According to Dima's wrt_elj_obc.m
0165 % script, for each time step, there's lines of depth averaged u and v
0166 % followed by all the u and v components at each vertical level. All lines
0167 % are prefixed with the current time in seconds relative to the start of
0168 % the model (or mean flow time series? God knows).
0169 
0170 f = fopen([casename, '_tide_uv.dat'], 'w');
0171 if f < 0
0172     error('Problem writing to _tide_uv.dat file. Check permissions and try again.')
0173 end
0174 
0175 % Number of elements in the boundaries.
0176 ne = Mobj.nObcElements;
0177 
0178 % Number of time steps.
0179 nt = length(Mobj.mf_times);
0180 
0181 % Number of vertical layers.
0182 nz = length(Mobj.siglay);
0183 
0184 % Create a format string for the each time step plus the number of boundary
0185 % elements.
0186 s = '%8d';
0187 for ss = 1:ne
0188     
0189     if ss < ne
0190         s = [s, '%8.4f'];
0191     else
0192         s = [s, '%8.4f\n'];
0193     end
0194 end
0195 
0196 % Do the depth averaged u then v for all nodes prefixed by the current
0197 % time. So, wrap the whole shebang in a loop through time.
0198 for t = 1:nt
0199     
0200     % Time since the start of the time series (in seconds).
0201     iint = (Mobj.mf_times(t) - Mobj.mf_times(1)) * 24 * 3600;
0202     
0203     % Dump the time and mean u and then mean v vectors.
0204     fprintf(f, s, [iint; mean(Mobj.meanflow_u(:, :, t), 2)]);
0205     fprintf(f, s, [iint; mean(Mobj.meanflow_v(:, :, t), 2)]);
0206     
0207     % Now, for each vertical layer, dump the u and v vectors, prefixed with
0208     % time.
0209     for zz = 1:nz
0210         fprintf(f, s, [iint; Mobj.meanflow_u(:, zz, t)]);
0211         fprintf(f, s, [iint; Mobj.meanflow_v(:, zz, t)]);
0212     end
0213 end
0214 
0215 fclose(f);
0216 
0217 %% _elj_obc.dat -- surface elevation time series at open boundary nodes.
0218 
0219 % This is almost identical to _tide_el.dat but lacks the time stamp in the
0220 % first column.
0221 
0222 f = fopen([casename, '_elj_obc.dat'], 'w');
0223 if f < 0
0224     error('Problem writing to _elj_obc.dat file. Check permissions and try again.')
0225 end
0226 
0227 nt = size(Mobj.surfaceElevation, 2);
0228 
0229 for t = 1:nt
0230     fprintf(f, '%8.4f', Mobj.surfaceElevation(:, t));
0231     fprintf(f, '\n');
0232 end
0233 
0234 if ftbverbose
0235     fprintf('end   : %s\n', subname)
0236 end
0237 
0238

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