Commit b8c678f7 authored by Pierre Cazenave's avatar Pierre Cazenave

Update the examples to work with the current version of the FVCOM toolbox.

parent a5747068
......@@ -18,15 +18,16 @@ function example_FVCOM_river()
%
%==============================================================================
t1 = 0; %greg2mjulian(2007,1,1,0,0,0);
t2 = 31; %greg2mjulian(2007,2,1,0,0,0);
t1 = greg2mjulian(2007,1,1,0,0,0);
t2 = greg2mjulian(2007,2,1,0,0,0);
time = t1:1:t2;
nTimes = prod(size(time));
nTimes = length(time);
% setup an event using Gaussian function
tmid = mean(time);
c = .1*(tmid-time(1));
flux = 400+300*exp(-(time-tmid).^2/(2.*c^2));
flux = 400+300*exp(-(time-tmid).^2/(2.*c^2))';
figure
plot(time,flux);
ylabel('flux m^3/s')
xlabel('time')
......@@ -36,13 +37,12 @@ sedload = .030*(flux.^1.40)/1000.; %sed conc in g/l
temp = 20*ones(nTimes,1);
salt = zeros(nTimes,1);
RiverFile = 'tst_riv.nc';
nRivnodes = 3;
RiverInfo1 = 'idealized estuary river';
RiverInfo2 = 'event profile';
RiverName = 'tstRiver';
RiverName = {'tstRiver'};
write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2)
write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)
% add sediment to the file
VarName = 'fine_sand';
......
......@@ -29,7 +29,7 @@ function example_FVCOM_tsobc(basename, time, nSiglay)
%==============================================================================
subname = 'example_FVCOM_tsobc';
global ftbverbose;
global ftbverbose
if ftbverbose
fprintf('\nbegin : %s\n', subname)
end
......@@ -49,9 +49,8 @@ for i = 1:nSiglay
end
% Initialize temperature/salinity arrays
temp = zeros(nObc,nSiglay,nTimes);
salt = zeros(nObc,nSiglay,nTimes);
% temp = zeros(nObc,nSiglay,nTimes);
% salt = zeros(nObc,nSiglay,nTimes);
% set variable temperature and salinity
% for i=1:nTimes
% obc_temp(i) = 18. + 2.*real(i-1)/nTimes;
......@@ -59,8 +58,8 @@ salt = zeros(nObc,nSiglay,nTimes);
% end
% set a constant temperature and salinity
obc_temp = ones(1, nTimes) * 13;
obc_salt = ones(1, nTimes) * 35;
obc_temp = 13;
obc_salt = 35;
%--------------------------------------------------------------
% dump to netcdf file
......@@ -68,8 +67,8 @@ obc_salt = ones(1, nTimes) * 35;
Mobj.siglev = siglev;
Mobj.siglay = siglay;
write_FVCOM_tsobc(basename,time,nSiglay,temp,salt,Mobj)
write_FVCOM_tsobc(basename,time,nSiglay,obc_temp,obc_salt,Mobj)
if ftbverbose;
if ftbverbose
fprintf('end : %s\n', subname);
end
function example_FVCOM_wind_ts_speed
% example file for FVCOM, time-varying/spatially constant wind forcing as speed
% Example forcing file for FVCOM, time-varying/spatially constant wind forcing
% as speed.
%
% function example_FVCOM_wind_ts_speed
%
......@@ -11,95 +11,55 @@ function example_FVCOM_wind_ts_speed
% It requires USER Modification to work
%
% INPUT
%
%
% OUTPUT:
% NetCDF WindFile
%
% EXAMPLE USAGE
% example_FVCOM_wind_ts_speed
%
% Author(s):
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
%==============================================================================
%warning off
% 2016-02-18 Updated to use the relevant functions from the toolbox.
%
%=============================================================================
subname = 'example_FVCOM_wind_ts';
fprintf('\n')
fprintf(['begin : ' subname '\n'])
global ftbverbose
ftbverbose = true;
if ftbverbose
fprintf('\nbegin : %s\n', subname)
end
%-----------------------------------------------------------------------------
% read a grid in
%-----------------------------------------------------------------------------
%------------------------------------------------------------------------------
Mobj = read_sms_mesh('2dm', './samples/tst.2dm');
%-----------------------------------------------------------------------------
% create a dataset
%------------------------------------------------------------------------------
%-----------------------------------------------------------------------------
% make a timeframe
% tbeg = greg2julian(2009,1,1,0,0,0)-2400000.5;
% tend = greg2julian(2010,1,1,0,0,0)-2400000.5;
tbeg = 0;
tend = 31;
time = tbeg:1:tend;
nTimes = numel(time);
tbeg = greg2mjulian(2009,1,1,0,0,0);
tend = greg2mjulian(2010,1,1,0,0,0);
data.time = tbeg:1/2:tend;
nTimes = numel(data.time);
% make up a fake time varying wind in m/s at 10-m above the water surface
u10 = 10*ones(nTimes,1);
v10 = zeros(nTimes,1);
data.u10.data = 10.*ones(nTimes, Mobj.nElems);
data.v10.data = 5.*ones(nTimes, Mobj.nElems);
%------------------------------------------------------------------------------
%-----------------------------------------------------------------------------
% write output to time-varying, spatially constant FVCOM wind file
%------------------------------------------------------------------------------
fvcom_forcing_file = 'tst_wind.nc';
nc = netcdf(fvcom_forcing_file, 'clobber');
nc.references = 'http://fvcom.smast.umassd.edu';
nc.source = 'single-point time-dependent surface forcing';
nc.institution = 'School for Marine Science and Technology' ;
nc.history = 'generated using the fvcom-toolbox';
% dimensions
nc('time') = 0;
% time vars
nc{'time'} = ncfloat('time');
nc{'time'}.long_name = 'time';
nc{'time'}.units = 'days since 1858-11-17 00:00:00';
nc{'time'}.format = 'modified julian day (MJD)';
nc{'time'}.time_zone = 'UTC';
nc{'Itime'} = ncint('time');
nc{'Itime'}.units = 'days since 1858-11-17 00:00:00';
nc{'Itime'}.format = 'modified julian day (MJD)';
nc{'Itime'}.time_zone = 'UTC';
nc{'Itime2'} = ncint('time');
nc{'Itime2'}.units = 'msec since 00:00:00';
nc{'Itime2'}.time_zone = 'UTC';
nc{'U10'} = ncfloat('time');
nc{'U10'}.long_name = 'Eastward Wind Velocity';
nc{'U10'}.standard_name = 'Wind Velocity';
nc{'U10'}.units = 'm/s';
nc{'U10'}.type = 'data';
nc{'V10'} = ncfloat('time');
nc{'V10'}.long_name = 'Northward Wind Velocity';
nc{'V10'}.standard_name = 'Wind Velocity';
nc{'V10'}.units = 'm/s';
nc{'V10'}.type = 'data';
% dump time
nc{'time'}(1:nTimes) = time;
nc{'Itime'}(1:nTimes) = floor(time);
nc{'Itime2'}(1:nTimes) = mod(time,1)*24*3600*1000.;
nc{'U10'}(1:nTimes) = u10;
nc{'V10'}(1:nTimes) = v10;
ierr = close(nc);
fprintf(['end : ' subname '\n'])
%-----------------------------------------------------------------------------
write_FVCOM_forcing(Mobj, 'tst', data, 'test forcing', '3.2.1')
if ftbverbose
fprintf('end : %s\n', subname)
end
\ No newline at end of file
......@@ -43,7 +43,7 @@ end
Mobj = add_coriolis(Mobj,'constant',31.0);
% check the time step and plot
Mobj = estimate_ts(Mobj);
Mobj = estimate_ts(Mobj, 3, 11);
plot_field(Mobj,Mobj.ts,'title','timestep (s)')
fprintf('estimated max external mode time step in seconds %f\n',min(Mobj.ts));
......@@ -87,12 +87,16 @@ plot_field(Mobj,Mobj.h,'title','domain','withextra',true,'showgrid',true);
example_FVCOM_river()
% add harmonic forcing to open boundary
set_spectide(Mobj)
% add Julian forcing to the open boundary using t_tide station
Mobj.Components = {'M2', 'S2'};
Mobj.period_obc = [44714.16, 43200];
Mobj.beta_love = [0, 0];
Mobj.equilibrium_amp = [0.1, 0.01];
Mobj.amp_obc = {repmat([3, 1], 1, Mobj.nObcNodes)};
Mobj.phase_obc = {repmat([3, 1], 1, Mobj.nObcNodes)};
set_spectide(Mobj, 2, 'tst_spectide.nc', 'Spectral tidal forcing')
% wind time series wind forcing example here
example_FVCOM_wind_ts
example_FVCOM_wind_ts_speed
% dump mesh and connectivity
write_FVCOM_grid(Mobj,'tst_grd.dat')
......
MESH2D
MESHNAME "mesh"
E3T 1 27 1 26 1
E3T 2 1 2 26 1
E3T 3 26 2 28 1
......
......@@ -4,6 +4,7 @@ BEGSCL
ND 845
NC 1570
NAME "elevation (Z)_interp"
TIMEUNITS seconds
TS 0 0
1.0000000e+01
1.0000000e+01
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment