From 2d73dd8d390f8994c4c37758bb06f5ea49ded10c Mon Sep 17 00:00:00 2001 From: Pierre Cazenave Date: Tue, 23 Apr 2013 16:03:57 +0100 Subject: [PATCH] Fix some remaining FORTRAN code (do loop and float function) to MATLAB. Also add a function description to match the format of the other tools in the toolbox. Also reformat the code to MATLAB standard format (indentation etc.). --- utilities/sigma_geo.m | 53 ++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/utilities/sigma_geo.m b/utilities/sigma_geo.m index 061a764..50ea881 100644 --- a/utilities/sigma_geo.m +++ b/utilities/sigma_geo.m @@ -1,16 +1,43 @@ -function dist = sigma_geo(nlev,p_sigma) +function dist = sigma_geo(nlev, p_sigma) +% Generate a geometric sigma coordinate distribution. +% +% Mobj = sigma_gen(nlev, p_sigma) +% +% DESCRIPTION: +% Generate a geometric vertical sigma coordinate distribution. +% +% INPUT: +% nlev: Number of sigma levels (layers + 1) +% p_sigma: 1 for uniform sigma layers, 2 for parabolic function. See +% page 308-309 in the FVCOM manual for examples. +% +% OUTPUT: +% dist: Geometric vertical sigma coordinate distribution. +% +% EXAMPLE USAGE: +% Mobj = read_sigma(21, 2.0) +% +% Author(s): +% Geoff Cowles (University of Massachusetts Dartmouth) +% Pierre Cazenave (Plymouth Marine Laboratory) +% +% Revision history +% 2013-04-23 Added help on the function and reformatted the code to +% remove to FORTRAN in the else block. + +dist = nan(1, nlev); kb = nlev; -if(p_sigma ==1) - for k=1:nlev - dist(k) = -((k-1)/float(kb-1))^p_sigma; - end; -else - for k=1:(kb+1)/2 - dist(k) = -((k-1)/float((kb+1)/2-1))^p_sigma/2; - end; - do k=(kb+1)/2+1:kb - dist(k) = ((kb-k)/float((kb+1)/2-1))^p_sigma/2-1.0; - end; -end; +if p_sigma == 1 + for k = 1:nlev + dist(k) = -((k-1)/(kb-1))^p_sigma; + end +else + for k = 1:(kb+1)/2 + dist(k) = -((k-1)/((kb+1)/2-1))^p_sigma/2; + end + for k = (kb+1)/2+1:kb + dist(k) = ((kb-k)/((kb+1)/2-1))^p_sigma/2-1.0; + end +end -- GitLab