Home > fvcom_prepro > init_lag.m

init_lag

PURPOSE ^

Write online Lagrangian initial conditions file.

SYNOPSIS ^

function init_lag(Mobj, timerange, type, file)

DESCRIPTION ^

 Write online Lagrangian initial conditions file.

 init_lag(Mobj, type, file)

 DESCRIPTION:
   Create the Lagrangian initial positions netCDF file.

 INPUT:
   Mobj - MATLAB mesh object containing fields:
       have_bath - boolean flag indicating whether the bathymetry is
       loaded.
       native_coord - string of the native coordinate type.
       h - water depth on nodes.
       xc, yc or lonc, lat - element centre coordinates (cartesian or
       spherical depending on native_coord).
   timerange - start and end date array (in Modified Julian Days).
   type - supply an array of element centre indices.
   file - path to the output netCDF file (string).

 OUTPUT:
   FVCOM forcing netCDF file(s)

 EXAMPLE USAGE:
   init = '/path/to/output/casename_lag.nc';
   init_lag(Mobj, 1, init);

 TODO:
   Add pathlength, group and mark as arguments to the function (currently
   set to 0, 1 and 0 respectively).

 Author(s):
   Geoff Cowles (University of Massachusetts Dartmouth)
   Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history
   2014-08-19 First version based on Geoff's original example_init_lag.m
   file.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function init_lag(Mobj, timerange, type, file)
0002 % Write online Lagrangian initial conditions file.
0003 %
0004 % init_lag(Mobj, type, file)
0005 %
0006 % DESCRIPTION:
0007 %   Create the Lagrangian initial positions netCDF file.
0008 %
0009 % INPUT:
0010 %   Mobj - MATLAB mesh object containing fields:
0011 %       have_bath - boolean flag indicating whether the bathymetry is
0012 %       loaded.
0013 %       native_coord - string of the native coordinate type.
0014 %       h - water depth on nodes.
0015 %       xc, yc or lonc, lat - element centre coordinates (cartesian or
0016 %       spherical depending on native_coord).
0017 %   timerange - start and end date array (in Modified Julian Days).
0018 %   type - supply an array of element centre indices.
0019 %   file - path to the output netCDF file (string).
0020 %
0021 % OUTPUT:
0022 %   FVCOM forcing netCDF file(s)
0023 %
0024 % EXAMPLE USAGE:
0025 %   init = '/path/to/output/casename_lag.nc';
0026 %   init_lag(Mobj, 1, init);
0027 %
0028 % TODO:
0029 %   Add pathlength, group and mark as arguments to the function (currently
0030 %   set to 0, 1 and 0 respectively).
0031 %
0032 % Author(s):
0033 %   Geoff Cowles (University of Massachusetts Dartmouth)
0034 %   Pierre Cazenave (Plymouth Marine Laboratory)
0035 %
0036 % Revision history
0037 %   2014-08-19 First version based on Geoff's original example_init_lag.m
0038 %   file.
0039 %
0040 %==========================================================================
0041 
0042 subname = 'init_lag';
0043 
0044 global ftbverbose;
0045 if ftbverbose
0046     fprintf('\nbegin : %s \n', subname)
0047 end
0048 
0049 tbeg = timerange(1);
0050 tend = timerange(2);
0051 
0052 if type == 1 % initialize at all elements
0053     xp   = Mobj.xc;
0054     yp   = Mobj.yc;
0055     nLag = Mobj.nElems;
0056 elseif type == 2 % initialize along a line of interest
0057     nLag = 10;
0058     p1 = [1.188363e6,194497];
0059     p2 = [1.188548e6,194996];
0060     xp = p1(1):(p2(1)-p1(1))/(nLag-1):p2(1);
0061     yp = p1(2):(p2(2)-p1(2))/(nLag-1):p2(2);
0062 elseif isvector(type)
0063 end
0064 
0065 % Dump the initial particle position file.
0066 nc = netcdf.create(file, 'clobber');
0067 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'references', 'http://fvcom.smast.umassd.edu, http://pml.ac.uk')
0068 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'source', 'init_lag.m')
0069 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'info', 'debugging')
0070 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
0071 
0072 % Dimensions
0073 nlag_dimid = netcdf.defDim(nc, 'nparticles', nLag);
0074 
0075 % Particle vars
0076 x_varid = netcdf.defVar(nc, 'x', 'NC_FLOAT', nlag_dimid);
0077 netcdf.putAtt(nc, x_varid, 'long_name', 'particle x position');
0078 netcdf.putAtt(nc, x_varid, 'units', 'm');
0079 
0080 y_varid = netcdf.defVar(nc, 'particle y position', 'NC_FLOAT', nlag_dimid);
0081 netcdf.putAtt(nc, y_varid, 'long_name', 'particle y position');
0082 netcdf.putAtt(nc, y_varid, 'units', 'm');
0083 
0084 z_varid = netcdf.defVar(nc, 'particle z position', 'NC_FLOAT', nlag_dimid);
0085 netcdf.putAtt(nc, z_varid, 'long_name', 'particle z position');
0086 netcdf.putAtt(nc, z_varid, 'units', 'm');
0087 
0088 pathlength_varid = netcdf.defVar(nc, 'pathlength', 'NC_FLOAT', nlag_dimid);
0089 netcdf.putAtt(nc, pathlength_varid, 'long_name', 'particle integrated path length');
0090 netcdf.putAtt(nc, pathlength_varid, 'units', 'm');
0091 
0092 tbeg_varid = netcdf.defVar(nc, 'tbeg', 'NC_FLOAT', nlag_dimid);
0093 netcdf.putAtt(nc, tbeg_varid, 'long_name', 'particle release time');
0094 netcdf.putAtt(nc, tbeg_varid, 'units', 'days since 1858-11-17 00:00:00');
0095 netcdf.putAtt(nc, tbeg_varid, 'format', 'modified julian day (MJD)');
0096 netcdf.putAtt(nc, tbeg_varid, 'time_zone', 'UTC');
0097 
0098 tend_varid = netcdf.defVar(nc, 'tbeg', 'NC_FLOAT', nlag_dimid);
0099 netcdf.putAtt(nc, tend_varid, 'long_name', 'particle freeze time');
0100 netcdf.putAtt(nc, tend_varid, 'units', 'days since 1858-11-17 00:00:00');
0101 netcdf.putAtt(nc, tend_varid, 'format', 'modified julian day (MJD)');
0102 netcdf.putAtt(nc, tend_varid, 'time_zone', 'UTC');
0103 
0104 group_varid = netdf.defVar(nc, 'group', 'NC_INT', nlag_dimid);
0105 netcdf.putAtt(nc, group_varid, 'long_name', 'particle group');
0106 netcdf.putAtt(nc, group_varid, 'units', '-');
0107 
0108 mark_varid = netdf.defVar(nc, 'mark', 'NC_INT', nlag_dimid);
0109 netcdf.putAtt(nc, mark_varid, 'long_name', 'particle mark');
0110 netcdf.putAtt(nc, mark_varid, 'units', '-');
0111 
0112 % End definitions
0113 netcdf.endDef(nc);
0114 
0115 % Dump vars
0116 netcdf.putVar(nc, x_varid, xp);
0117 netcdf.putVar(nc, y_varid, yp);
0118 netcdf.putVar(nc, z_varid, zp);
0119 netcdf.putVar(nc, tbeg_varid, tbeg);
0120 netcdf.putVar(nc, tend_varid, tend);
0121 netcdf.putVar(nc, group_varid, 1);
0122 netcdf.putVar(nc, mark_varid, 0);
0123 netcdf.putVar(nc, pathlength_varid, 0);
0124 
0125 % Close netCDF file
0126 netcdf.close(nc);
0127 
0128 if ftbverbose; fprintf('end   : %s\n', subname); end

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