Met Wind Direction MATLAB Implementation

function [wdir, status] = compute_wind_direction ( input_data, mag_var, offset )
% COMPUTE_WIND_DIRECTION:  computes wind_direction (usually just adjusts it)
%
% USAGE:  [wd, status] = compute_wind_direction ( input_wd, mag_var, offset );
%
% PARAMETERS:
% Input:
%    input_data:  
%       This is usually just the wind direction as directly measured by
%       the wind sensor, in degrees relative to magnetic north.
%    mag_var:
%       Magnetic variation in degrees.  This helps adjust the wind direction
%       to where 0 degrees means true north.
%    offset:
%       This is an ad-hoc adjustment factor to use in case a wind instrument
%       is calibrated incorrectly.
% Output:
%    wdir: 
%       Wind direction in units of angular degrees, relative to true north.
%    status:
%       -1 for failure
%            

status = -1;

switch nargin

	case 0
		help compute_wind_direction;
		return

	case 1
		mag_var = 0;
		offset = 0;

	case 2
		offset = 0;

	case 3
		;

	otherwise
		fprintf ( 2, '%s:  needs at least one input argument.\n', mfilename );
		help compute_wind_direction;
		return

end


total_offset = mag_var + offset ;
		
wdir = mod ( (input_data+total_offset), 360 );
status = 1;
return