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.

read_sigma.m 2.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
function Mobj = read_sigma(Mobj, sigmafile)
% Read an FVCOM sigma layers file and output z values into Mobj.sigmaz.
% 
% Mobj = read_sigma(Mobj, sigmafile)
% 
% DESCRIPTION:
%   Read a sigma file and calculate the sigma layer depths
% 
% INPUT:
%   Mobj:       Mesh object which must contain Mobj.h (depths).
%   sigmafile : Full path to an FVCOM sigma.dat file.
% 
% OUTPUT:
14 15 16
%   Mobj:       Mesh object with two new fields (siglayz and siglevz) which
%               contain depths of the sigma layers and levels at each grid
%               node.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 101
% 
% EXAMPLE USAGE:
%   read_sigma(Mobj, 'sigma.dat')
% 
% Author(s):
%   Pierre Cazenave (Plymouth Marine Laboratory)
% 
% Revision history
%   2013-01-08 Based on the code in show_sigma.m but instead of calculating
%   sigma layers along a user-defined line, the depths are calculated for
%   each node in the unstructured grid.

subname = 'read_sigma';

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

fid = fopen(sigmafile,'r');
if(fid  < 0)
    error(['file: ' sigmafile ' does not exist']);
end

while ~feof(fid)
    line = fgetl(fid);
    if isempty(line) || strncmp(line, '!', 1) || ~ischar(line)
        continue
    end
    key = lower(line(1:3));
    C = strtrim(regexpi(line, '=', 'split'));
    switch key
        case 'num'
            nlev = str2double(C{2});
        case 'sig'
            sigtype = C{2};
        case 'du '
            du = str2double(C{2});
        case 'dl '
            dl = str2double(C{2});
        case 'min'
            min_constant_depth = str2double(C{2});
        case 'ku '
            ku = str2double(C{2});
        case 'kl '
            kl = str2double(C{2});
        case 'zku'
            s = str2double(regexp(C{2}, ' ', 'split'));
            zku = zeros(ku, 1);
            for i = 1:ku
                zku(i) = s(i);
            end
        case 'zkl'
            s = str2double(regexp(C{2}, ' ', 'split'));
            zkl = zeros(kl, 1);
            for i = 1:kl
                zkl(i) = s(i);
            end
    end
end

if ftbverbose
    fprintf('nlev %d\n',nlev)
    fprintf('sigtype %s\n',sigtype)
    fprintf('du %d\n',du)
    fprintf('dl %d\n',dl)
    fprintf('min_constant_depth %f\n',min_constant_depth)
    fprintf('ku %d\n',ku)
    fprintf('kl %d\n',kl)
    fprintf('zku %d\n',zku)
    fprintf('zkl %d\n',zkl)
end

% calculate the sigma distributions at each grid node
switch lower(sigtype)
    case 'generalized'
        z = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, ...
            Mobj.z(i), min_constant_depth);
    case 'uniform'
        z = 0:-1/double(nlev-1):-1;
    otherwise
        error('Can''t do that sigtype')
end

102 103 104 105 106
% Create a siglay variable (i.e. midpoint in the sigma levels).
zlay = z(1:end-1) + (diff(z)/2);

Mobj.siglevz = repmat(Mobj.h, 1, nlev) .* repmat(z, Mobj.nVerts, 1);
Mobj.siglayz = repmat(Mobj.h, 1, nlev-1) .* repmat(zlay, Mobj.nVerts, 1);
107 108 109 110

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