Home > mrg > MRG_utilities > mrg_cart_to_pol.m

mrg_cart_to_pol

PURPOSE ^

Converts U and V velcity data into magnitude and direction

SYNOPSIS ^

function [dir,mag] = mrg_cart_to_pol(curr_east,curr_north,wind)

DESCRIPTION ^

 Converts U and V velcity data into magnitude and direction

 INPUT
   curr_east   A positive integer defining the column number for the U
               component in the DFS0 file.
   curr_north  A positive integer defining the column number for the V 
               component in the DFS0 file.
   wind        Is either 1 if the input data is wind data, otherwise 0.  
               See NOTES.
 
 OUTPUT
   mag         Magnitude
   dir         Direction (in degrees)


 NOTES
   Wind directions are typically specifiy as the direction the wind is
   *coming from*, whereas other directions (e.g. currents) are specified
   as the direction they are *going to*.  The wind input allows for this,
   and ensures wind directions are calcuated correctly.

   This is a generic version of mrg_dfs0_cart_to_pol.  Designed primariliy
   so that Dan doesn't make so many silly mistakes.

 LICENCE
   Created B. Elsaesser (b.elsaesser@qub.ac.uk)
   Updated by Daniel Pritchard (www.pritchard.co)
   Original copyright B. Elsaesser.  Rewritten code distributed under a
   creative commons CC BY-SA licence. See here:
   http://creativecommons.org/licenses/by-sa/3.0/

 DEVELOPMENT
   v 1.0   Feb 2013
           DP. First version.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dir,mag] = mrg_cart_to_pol(curr_east,curr_north,wind)
0002 % Converts U and V velcity data into magnitude and direction
0003 %
0004 % INPUT
0005 %   curr_east   A positive integer defining the column number for the U
0006 %               component in the DFS0 file.
0007 %   curr_north  A positive integer defining the column number for the V
0008 %               component in the DFS0 file.
0009 %   wind        Is either 1 if the input data is wind data, otherwise 0.
0010 %               See NOTES.
0011 %
0012 % OUTPUT
0013 %   mag         Magnitude
0014 %   dir         Direction (in degrees)
0015 %
0016 %
0017 % NOTES
0018 %   Wind directions are typically specifiy as the direction the wind is
0019 %   *coming from*, whereas other directions (e.g. currents) are specified
0020 %   as the direction they are *going to*.  The wind input allows for this,
0021 %   and ensures wind directions are calcuated correctly.
0022 %
0023 %   This is a generic version of mrg_dfs0_cart_to_pol.  Designed primariliy
0024 %   so that Dan doesn't make so many silly mistakes.
0025 %
0026 % LICENCE
0027 %   Created B. Elsaesser (b.elsaesser@qub.ac.uk)
0028 %   Updated by Daniel Pritchard (www.pritchard.co)
0029 %   Original copyright B. Elsaesser.  Rewritten code distributed under a
0030 %   creative commons CC BY-SA licence. See here:
0031 %   http://creativecommons.org/licenses/by-sa/3.0/
0032 %
0033 % DEVELOPMENT
0034 %   v 1.0   Feb 2013
0035 %           DP. First version.
0036 
0037 if ~all(size(curr_east)==size(curr_north))
0038     error('curr_east and curr_north must be the same size!')
0039 end
0040 
0041 [dir,mag] = cart2pol(curr_north,curr_east);
0042 
0043 if wind
0044     dir = dir*180/pi + 180;
0045 else
0046     dir = dir*180/pi;
0047     index = ~(dir > 0);
0048     dir = dir+index*360;
0049 end
0050 
0051 end

Generated on Thu 29-May-2014 21:29:53 by m2html © 2005