Due to a shift in policy, from 0900 GMT on Wednesday 14th July 2021, we will be disabling ssh access to the server for external users. External users who wish to continue to access code repositories on the server will need to switch to using https. This can be accomplished in the following way: 1) On the repo on gitlab, use the clone dialogue and select ‘Clone with HTTPS’ to get the address of the repo; 2) From within the checkout of your repo run: $ git remote set-url origin HTTPS_ADDRESS. Here, replace HTTPS_ADDRESS with the address you have just copied from GitLab. Pulls and pushes will now require you to enter a username and password rather than using a ssh key. If you would prefer not to enter a password each time, you might consider caching your login credentials.

add_var_FVCOM_river.m 2.88 KB
Newer Older
Pierre Cazenave's avatar
Pierre Cazenave committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData)
% 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
%   
%==============================================================================

34
%warning off
Pierre Cazenave's avatar
Pierre Cazenave committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

subname = 'add_var_FVCOM_river';
global ftbverbose;
if(ftbverbose);
  fprintf('\n')
  fprintf(['begin : ' subname '\n'])
end;

if(ftbverbose);fprintf('adding variable %s to file %s\n',VarName,RiverFile); end;

%------------------------------------------------------------------------------
% Open River Netcdf and read dimensions
%------------------------------------------------------------------------------
if(~exist(RiverFile))
	error(['file: ' RiverFile ' does not exist']);
end;

nc = netcdf(RiverFile, 'w');  
 
% read dimensions
flux = nc{'river_flux'}(:,:);
[nTimes,nRivnodes]= size(flux);

% make sure time dimension matches FVCOM river dims
tempTimes = prod(size(VarData));
if(nTimes ~= tempTimes)
	fprintf('# of time frames in file %s is %d\n',RiverFile,tempTimes)
	fprintf('# of time frames in VarData is %d\n',nTimes)
	error('you have chosen the wrong vocation')
end;


%------------------------------------------------------------------------------
% Write variable definition and data and close file
%------------------------------------------------------------------------------

% set field
river_field = zeros(nTimes,nRivnodes);
for i=1:nTimes
	river_field(i,1:nRivnodes) = VarData(i);
end;



%--------------------------------------------------------------
% dump to netcdf file
%--------------------------------------------------------------

% open boundary forcing
nc = netcdf(RiverFile, 'w');    
nc{VarName} = ncfloat('time','rivers');
nc{VarName}.long_name = VarLongName; 
nc{VarName}.units     = VarUnits;   

% dump dynamic data
for i=1:nTimes
  nc{VarName}(i,1:nRivnodes) = river_field(i,1:nRivnodes); 
end;

nc = close(nc);    


if(ftbverbose);
  fprintf(['end   : ' subname '\n'])
end;