Home > fvcom_prepro > write_FVCOM_meanflow.m

write_FVCOM_meanflow

PURPOSE ^

Export mean flow forcing at the open boundary to NetCDF.

SYNOPSIS ^

function write_FVCOM_meanflow(Mobj, ncfile, data)

DESCRIPTION ^

 Export mean flow forcing at the open boundary to NetCDF.

 function write_FVCOM_meanflow(Mobj, ncfile, data)

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

 INPUT:
   Mobj    - MATLAB mesh object (with fields mf_time, siglay, siglev,
               nObcElements and read_obc_elements).
   ncfile  - Output NetCDF file name.
   data    - 2D array of mean flow along the open boundary sized
               (nobcelems, time).

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

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

 TODO:
    Add support for multiple open boundaries (currently hard limit of
    one).

 Revision history
    2013-02-20 - First version.
    2013-02-28 - Change output of velocities to be at the boundary element
    centres rather than the boundary nodes.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function write_FVCOM_meanflow(Mobj, ncfile, data)
0002 % Export mean flow forcing at the open boundary to NetCDF.
0003 %
0004 % function write_FVCOM_meanflow(Mobj, ncfile, 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 %               nObcElements and read_obc_elements).
0012 %   ncfile  - Output NetCDF file name.
0013 %   data    - 2D array of mean flow along the open boundary sized
0014 %               (nobcelems, time).
0015 %
0016 % OUTPUT:
0017 %    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
0018 %    named ncfile.
0019 %
0020 % Author(s):
0021 %    Pierre Cazenave (Plymouth Marine Laboratory)
0022 %
0023 % TODO:
0024 %    Add support for multiple open boundaries (currently hard limit of
0025 %    one).
0026 %
0027 % Revision history
0028 %    2013-02-20 - First version.
0029 %    2013-02-28 - Change output of velocities to be at the boundary element
0030 %    centres rather than the boundary nodes.
0031 %
0032 %==========================================================================
0033 
0034 subname = 'write_FVCOM_meanflow';
0035 
0036 global ftbverbose
0037 if ftbverbose
0038     fprintf('\n'); fprintf(['begin : ' subname '\n']);
0039 end
0040 
0041 % open new NetCDF file
0042 nc = netcdf.create(ncfile, 'clobber');
0043 
0044 % define global attributes
0045 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'type', 'FVCOM MEANFLOW TIME SERIES FILE')
0046 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'title', 'FVCOM MEANFLOW TIME SERIES data for open boundary')
0047 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
0048 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'filename', ncfile)
0049 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'Conventions', 'CF-1.0')
0050 
0051 % define dimensions
0052 nmfcell_dimid = netcdf.defDim(nc, 'nmfcell', Mobj.nObcElements);
0053 time_dimid = netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
0054 siglay_dimid = netcdf.defDim(nc, 'siglay', size(Mobj.siglay, 2));
0055 siglev_dimid = netcdf.defDim(nc, 'siglev', size(Mobj.siglev, 2));
0056 
0057 % define variables
0058 time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
0059 netcdf.putAtt(nc, time_varid, 'long_name', 'time');
0060 netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
0061 netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
0062 netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
0063 
0064 itime_varid = netcdf.defVar(nc, 'Itime', 'NC_INT', time_dimid);
0065 netcdf.putAtt(nc, itime_varid, 'units', 'days since 1858-11-17 00:00:00');
0066 netcdf.putAtt(nc, itime_varid, 'format', 'modified julian day (MJD)');
0067 netcdf.putAtt(nc, itime_varid, 'time_zone', 'UTC');
0068 
0069 itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', time_dimid);
0070 netcdf.putAtt(nc, itime2_varid, 'units', 'msec since 00:00:00');
0071 netcdf.putAtt(nc, itime2_varid, 'time_zone', 'UTC');
0072 
0073 nmfcell_varid = netcdf.defVar(nc, 'I_MFCELL_GL', 'NC_INT', nmfcell_dimid);
0074 netcdf.putAtt(nc, nmfcell_varid, 'long_name', 'Open Boundary Cell Number');
0075 netcdf.putAtt(nc, nmfcell_varid, 'grid', 'obc_grid');
0076 netcdf.putAtt(nc, nmfcell_varid, 'type', 'data');
0077 
0078 mfdist_varid = netcdf.defVar(nc, 'MFDIST', 'NC_FLOAT', [siglay_dimid, nmfcell_dimid]);
0079 netcdf.putAtt(nc, mfdist_varid, 'long_name', 'Mean Flow Flux Vertical Distribution');
0080 netcdf.putAtt(nc, mfdist_varid, 'units', 'no units');
0081 netcdf.putAtt(nc, mfdist_varid, 'grid', 'obc_grid');
0082 netcdf.putAtt(nc, mfdist_varid, 'type', 'data');
0083 
0084 dmfqdis_varid = netcdf.defVar(nc, 'DMFQDIS', 'NC_FLOAT', [nmfcell_dimid, time_dimid]);
0085 netcdf.putAtt(nc, dmfqdis_varid, 'long_name', 'open boundary mean flow flux');
0086 netcdf.putAtt(nc, dmfqdis_varid, 'units', 'm^3/s');
0087 netcdf.putAtt(nc, dmfqdis_varid, 'grid', 'obc_grid');
0088 netcdf.putAtt(nc, dmfqdis_varid, 'type', 'data');
0089 
0090 % end definitions
0091 netcdf.endDef(nc);
0092 
0093 % write data
0094 netcdf.putVar(nc, time_varid, 0, numel(Mobj.mf_times), Mobj.mf_times);
0095 netcdf.putVar(nc, itime_varid, floor(Mobj.mf_times));
0096 netcdf.putVar(nc, itime2_varid, 0, numel(Mobj.mf_times), mod(Mobj.mf_times, 1) * 24 * 3600 * 1000);
0097 netcdf.putVar(nc, nmfcell_varid, Mobj.read_obc_elements{1});
0098 % MFDIST is calculated here as the diff of the sigma levels. This should
0099 % work for uniform and gaussian etc. distributions so long as Mobj.siglev
0100 % has the right values in it.
0101 netcdf.putVar(nc, mfdist_varid, repmat(abs(diff(Mobj.siglev)), [numel([Mobj.read_obc_elements{:}]), 1])');
0102 netcdf.putVar(nc, dmfqdis_varid, [0, 0], [numel(Mobj.read_obc_elements{1}), numel(Mobj.mf_times)], data);
0103 
0104 netcdf.close(nc);
0105 
0106 if ftbverbose
0107     fprintf(['end   : ' subname '\n'])
0108 end
0109

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