% function [utide_am1 utide_ph1 vtide_am1 vtide_ph1] = tide_rot(utide_am0,utide_ph0,vtide_am0,vtide_ph0,angleCS, angleSN) % % Rotate tidal current parameter from NS and EW to a new coordinate defined by angleCS and angleSN % % Input: utide_am0, utide_ph0(in deg) % vtide_am0, vtide_ph0(in deg) % AngleCS angleSN: cos(alpha), sin(alpha); % alpha is the angle between new coordinate (utide_am1, vtide_am1) and due east % % Output: utide_am1, utide_ph1(in deg) % vtide_am1, vtide_ph1(in deg); % % Both input and output are assumed (1 L) array % % XC WANG /07/12/2012 % function [utide_am1 utide_ph1 vtide_am1 vtide_ph1] = tide_rot(utide_am0,utide_ph0,vtide_am0,vtide_ph0,angleCS,angleSN) rad2deg = 180/pi ; deg2rad = pi/180 ; % Convert deg to radian utide_ph0 = utide_ph0*deg2rad ; vtide_ph0 = vtide_ph0*deg2rad ; u1_p1 = utide_am0.*angleCS.*cos(utide_ph0) + vtide_am0.*angleSN.*cos(vtide_ph0) ; u1_p2 = utide_am0.*angleCS.*sin(utide_ph0) + vtide_am0.*angleSN.*sin(vtide_ph0) ; utide_am1 = sqrt(u1_p1.*u1_p1 + u1_p2.*u1_p2) ; sin1 = u1_p2 ./ utide_am1 ; cos1 = u1_p1 ./ utide_am1 ; utide_ph1 = atan2(sin1, cos1) ; utide_ph1 = utide_ph1*rad2deg ; v1_p1 = -utide_am0.*angleSN.*cos(utide_ph0) + vtide_am0.*angleCS.*cos(vtide_ph0) ; v1_p2 = -utide_am0.*angleSN.*sin(utide_ph0) + vtide_am0.*angleCS.*sin(vtide_ph0) ; vtide_am1 = sqrt(v1_p1 .* v1_p1 + v1_p2.*v1_p2) ; sin1 = v1_p2 ./ vtide_am1 ; cos1 = v1_p1 ./ vtide_am1 ; vtide_ph1 = atan2(sin1, cos1) ; vtide_ph1 = vtide_ph1*rad2deg ; return end