


add time dependent scalar variable to a Riverfile
function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData)
DESCRIPTION:
Write an additional scalar variable (e.g. sediment, DO) to a NetCDF
River file. Note that the concentration of the scalar variable
is set the same at all river points in the file so it is assumed
that even if the file contains multiple nodes, they all refer to the same
river.
INPUT
RiverFile: FVCOM 3.x NetCDF river forcing file
VarName: Variable name (will be the name of the array in the NetCDF file)
VarLongName: Variable attribute "long_name"
VarUnits: Variable attribute "units"
VarData: 1-D Time series of variable data of exact same dimensions as
the river flux
OUTPUT:
Modified FVCOM RiverFile
EXAMPLE USAGE
add_var_FVCOM_river('tst_riv.nc','medium_sand','medium sand','kg-m^-3',sand_ts)
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Revision history
==============================================================================

0001 function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData) 0002 % add time dependent scalar variable to a Riverfile 0003 % 0004 % function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData) 0005 % 0006 % DESCRIPTION: 0007 % Write an additional scalar variable (e.g. sediment, DO) to a NetCDF 0008 % River file. Note that the concentration of the scalar variable 0009 % is set the same at all river points in the file so it is assumed 0010 % that even if the file contains multiple nodes, they all refer to the same 0011 % river. 0012 % 0013 % INPUT 0014 % RiverFile: FVCOM 3.x NetCDF river forcing file 0015 % VarName: Variable name (will be the name of the array in the NetCDF file) 0016 % VarLongName: Variable attribute "long_name" 0017 % VarUnits: Variable attribute "units" 0018 % VarData: 1-D Time series of variable data of exact same dimensions as 0019 % the river flux 0020 % 0021 % OUTPUT: 0022 % Modified FVCOM RiverFile 0023 % 0024 % EXAMPLE USAGE 0025 % add_var_FVCOM_river('tst_riv.nc','medium_sand','medium sand','kg-m^-3',sand_ts) 0026 % 0027 % Author(s): 0028 % Geoff Cowles (University of Massachusetts Dartmouth) 0029 % 0030 % Revision history 0031 % 0032 %============================================================================== 0033 0034 warning off 0035 0036 subname = 'add_var_FVCOM_river'; 0037 global ftbverbose; 0038 if(ftbverbose); 0039 fprintf('\n') 0040 fprintf(['begin : ' subname '\n']) 0041 end; 0042 0043 if(ftbverbose);fprintf('adding variable %s to file %s\n',VarName,RiverFile); end; 0044 0045 %------------------------------------------------------------------------------ 0046 % Open River Netcdf and read dimensions 0047 %------------------------------------------------------------------------------ 0048 if(~exist(RiverFile)) 0049 error(['file: ' RiverFile ' does not exist']); 0050 end; 0051 0052 nc = netcdf(RiverFile, 'w'); 0053 0054 % read dimensions 0055 flux = nc{'river_flux'}(:,:); 0056 [nTimes,nRivnodes]= size(flux); 0057 0058 % make sure time dimension matches FVCOM river dims 0059 tempTimes = prod(size(VarData)); 0060 if(nTimes ~= tempTimes) 0061 fprintf('# of time frames in file %s is %d\n',RiverFile,tempTimes) 0062 fprintf('# of time frames in VarData is %d\n',nTimes) 0063 error('you have chosen the wrong vocation') 0064 end; 0065 0066 0067 %------------------------------------------------------------------------------ 0068 % Write variable definition and data and close file 0069 %------------------------------------------------------------------------------ 0070 0071 % set field 0072 river_field = zeros(nTimes,nRivnodes); 0073 for i=1:nTimes 0074 river_field(i,1:nRivnodes) = VarData(i); 0075 end; 0076 0077 0078 0079 %-------------------------------------------------------------- 0080 % dump to netcdf file 0081 %-------------------------------------------------------------- 0082 0083 % open boundary forcing 0084 nc = netcdf(RiverFile, 'w'); 0085 nc{VarName} = ncfloat('time','rivers'); 0086 nc{VarName}.long_name = VarLongName; 0087 nc{VarName}.units = VarUnits; 0088 0089 % dump dynamic data 0090 for i=1:nTimes 0091 nc{VarName}(i,1:nRivnodes) = river_field(i,1:nRivnodes); 0092 end; 0093 0094 nc = close(nc); 0095 0096 0097 if(ftbverbose); 0098 fprintf(['end : ' subname '\n']) 0099 end; 0100