; Subroutine TRUEWIND ; Comments updated: 10/01/97 ; Developed by: Shawn R. Smith and Mark A. Bourassa ; Programmed by: Jiraporn Whalley and Mylene Remigio ; Last updated: 9/30/2014 ; Direct questions to: wocemet@coaps.fsu.edu ; 9/30/2014 :Version 2 - Arturo Valery ; If the true wind has speed and its coming from the north ; then its direction should be 360deg. The problem was fixed ; in which the programs’s output showed 0deg instead of 360deg. ; This routine will compute meteorological true winds (direction from ; which wind is blowing, relative to true north; and speed relative to ; the fixed earth). ; INPUT VALUES: ; num int Number of observations in input (crse, cspd, ; wdir, wspd, hd) and output (adir, tdir, tspd) ; data arrays. ALL ARRAYS MUST BE OF EQUAL ; LENGTH. ; sel int Sets option for diagnostic output. There are ; four settings: ; ; Option 4: Calculates true winds from input ; arrays with no diagnostic output or ; warnings. NOT RECOMMENDED. ; Option 3: [DEFAULT] Diagnostic output lists the ; array index and corresponding ; variables that either violate the ; range checks or are equal to the ; missing value. An additional table ; lists the number of observation times ; with no missing values, some (but not ; all) missing values, and all missing ; values; as well as similar totals for ; the observation times that fail the ; range checks. Range checks identify ; negative input values and verify ; directions to be between 0 and 360 ; degrees. ; Option 2: In addition to the default ; diagnostics (option 3), a table of ; all input and output values for ; observation times with missing data ; is provided. ; Option 1: Full diagnostics -- In addition to ; the diagnostics provided by option 2 ; and 3, a complete data chart is ; output. The table contains input and ; output values for all observation ; times passed to truewind. ; crse float array Course TOWARD WHICH the vessel is moving over ; the ground. Referenced to true north and the ; fixed earth. ; cspd float array Speed of vessel over the ground. Referenced ; to the fixed earth. ; hd float array Heading toward which bow of vessel is pointing. ; Referenced to true north. ; zlr float Zero line reference -- angle between bow and ; zero line on anemometer. Direction is clockwise ; from the bow. (Use bow=0 degrees as default ; when reference not known.) ; wdir float array Wind direction measured by anemometer, ; referenced to the ship. ; wspd float array Wind speed measured by anemometer,referenced to ; the vessel's frame of reference. ; wmis float array Five element array containing missing values for ; crse, cspd, wdir, wspd, and hd. In the output, the ; missing value for tdir is identical to the ; missing value specified in wmis for wdir. ; Similarly, tspd uses the missing value assigned ; to wmis for wspd. ; *** WDIR MUST BE METEOROLOGICAL (DIRECTION FROM)! CRSE AND CSPD MUST ; BE RELATIVE TO A FIXED EARTH! *** ; OUTPUT VALUES: ; tdir float array True wind direction - referenced to true north ; and the fixed earth with a direction from which ; the wind is blowing (meteorological). ; tspd float array True wind speed - referenced to the fixed earth. ; adir float array Apparent wind direction (direction measured by ; wind vane, relative to true north). IS ; REFERENCED TO TRUE NORTH & IS DIRECTION FROM ; WHICH THE WIND IS BLOWING. Apparent wind ; direction is the sum of the ship relative wind ; direction (measured by wind vane relative to the ; bow), ship's heading, and the zero-line ; reference angle. NOTE: The apparent wind speed ; has a magnitude equal to the wind speed measured ; by the anemometer. ; DIAGNOSTIC OUTPUT: ; nw int Number of observation times for which tdir and ; tspd were calculated (without missing values) ; nwpm int Number of observation times with some values ; (crse, cspd, wdir, wspd, hd) missing. tdir, tspd ; set to missing value. ; nwam int Number of observation times with all values ; (crse, cspd, wdir, wspd, hd) missing. tdir, tspd set ; to missing value. ; nwf int Number of observation times where the program ; fails -- at least one of the values (crse, cspd, ; wdir, wspd, hd) is invalid ;*********************************************************************** pro truewind, num, sel, crse, cspd, wdir, zlr, hd, adir, wspd, wmis, $ tdir, tspd, nw, nwpm, nwam, nwf ; INITIALIZE VALUES. x = 0.0 y = 0.0 nw = 0 nwpm = 0 nwam = 0 nwf = 0 ; LOOP OVER 'NUM' VALUES. for i = 0, num-1 do begin case 1 of ; CHECK COURSE, SHIP SPEED, HEADING, WIND DIRECTION, AND WIND SPEED ; FOR VALID VALUES (i.e. neither missing nor outside physically ; acceptable ranges). ( ((crse(i) LT 0.0)OR(crse(i) GT 360.0)) AND $ (crse(i) NE wmis(0)) ) OR ( (cspd(i) LT 0.0) AND $ (cspd(i) NE wmis(1)) ) OR ( ((wdir(i) LT 0.0)OR $ (wdir(i) GT 360.0) ) AND (wdir(i) NE wmis(2)) ) OR $ ((wspd(i) LT 0.0) AND (wspd(i) NE wmis(3))) OR $ ( ((hd(i) LT 0.0)OR(hd(i) GT 360.0)) AND $ (hd(i) NE wmis(4)) ): begin ; WHEN SOME OR ALL OF INPUT DATA FAILS RANGE CHECK, SET TRUE WINDS TO ; MISSING. STEP INDEX FOR INPUT VALUE(S) BEING OUT OF RANGE nwf = nwf + 1 tdir(i) = wmis(2) tspd(i) = wmis(3) if(crse(i) NE wmis(0)) AND (cspd(i) NE wmis(1)) AND $ (wdir(i) NE wmis(2)) AND (wspd(i) NE wmis(3)) AND $ (hd(i) NE wmis(4)) then begin ; STEP INDEX FOR ALL INPUT VALUES BEING NON-MISSING nw = nw + 1 endif else begin if(crse(i) NE wmis(0)) OR (cspd(i) NE wmis(1)) OR $ (wdir(i) NE wmis(2)) OR (wspd(i) NE wmis(3)) OR $ (hd(i) NE wmis(4)) then begin ; STEP INDEX FOR PART OF INPUT VALUES BEING MISSING nwpm = nwpm + 1 endif else begin ; STEP INDEX FOR ALL INPUT VALUES BEING MISSING nwam = nwam + 1 endelse endelse end ; WHEN COURSE, SHIP SPEED, HEADING, WIND DIRECTION, AND WIND SPEED ; ARE ALL IN RANGE AND NON-MISSING, THEN COMPUTE TRUE WINDS. (crse(i) NE wmis(0)) AND (cspd(i) NE wmis(1)) AND $ (wdir(i) NE wmis(2)) AND (wspd(i) NE wmis(3)) AND $ (hd(i) NE wmis(4)) : begin nw = nw + 1 ; CONVERT FROM NAVIGATIONAL COORDINATES TO ANGLES COMMONLY USED IN ; MATHEMATICS mcrse = 90.0 - crse(i) ; KEEP VALUES BETWEEN 0 AND 360 DEGREES if(mcrse LE 0.0) then $ mcrse = mcrse + 360.0 ; CHECK ZLR FOR VALID VALUE. IF NOT VALID, SET EQUAL TO ZERO. if(zlr LT 0.0) OR (zlr GT 360.0) then $ zlr = 0.0 ; CALCULATE APPARENT WIND DIRECTION adir(i) = hd(i) + wdir(i) + zlr ; KEEP ADIR BETWEEN 0 AND 360 DEGREES while (adir(i) GE 360.0) do $ adir(i) = adir(i) - 360.0 ; CONVERT FROM METEOROLOGICAL COORDINATES TO ANGLES COMMONLY UESD ; IN MATHEMATICS mwdir = 270.0 - adir(i) ; KEEP VALUES BETWEEN 0 AND 360 DEGREES if(mwdir LE 0.0) then $ mwdir = mwdir + 360.0 if(mwdir GE 360.0) then $ mwdir = mwdir - 360.0 ; DETERMINE THE EAST-WEST AND NORTH-SOUTH VECTOR COMPONENTS OF ; THE TRUE WIND x = wspd(i) * COS(mwdir * !DTOR) + cspd(i) * COS(mcrse * !DTOR) y = wspd(i) * SIN(mwdir * !DTOR) + cspd(i) * SIN(mcrse * !DTOR) ; USE THE TWO VECTOR COMPONENTS TO CALCULATE THE TRUE WIND SPEED tspd(i) = (x^2 + y^2)^0.5 calm_flag = 1 ; DETERMINE THE ANGLE FOR THE TRUE WIND if(ABS(x) GT 0.00001) then begin mtruedir = ATAN(y, x) / !DTOR endif else begin if(ABS(y) GT 0.00001) then begin mtruedir = 180.0 - 90.0 * y / ABS(y) endif else begin mtruedir = 270.0 calm_flag = 0.0 endelse endelse ; CONVERT FROM THE COMMON MATHEMATICAL ANGLE COORDINATE TO THE ; METEOROLOGICAL WIND DIRECTION tdir(i) = 270.0 - mtruedir ; MAKE SURE THAT THE TRUE WIND DIRECTION IS BETWEEN 0 AND 360 DEGREES while (tdir(i) LT 0.0) do $ tdir(i) = (tdir(i) + 360.0) * calm_flag while (tdir(i) GE 360.0) do $ tdir(i) = (tdir(i) - 360.0) * calm_flag if ((calm_flag EQ 1) AND (tdir(i) LT 0.0001)) THEN tdir(i) = 360 x = 0.0 y = 0.0 end ; WHEN COURSE, SHIP SPEED, APPARENT DIRECTION, AND WIND SPEED ; ARE ALL IN RANGE BUT PART OF THESE INPUT VALUES ARE MISSING, ; THEN SET TRUE WIND DIRECTION AND SPEED TO MISSING. (crse(i) NE wmis(0)) OR (cspd(i) NE wmis(1)) OR $ (wdir(i) NE wmis(2)) OR (wspd(i) NE wmis(3)) OR $ (hd(i) NE wmis(4)) : begin nwpm = nwpm + 1 tdir(i) = wmis(2) tspd(i) = wmis(3) end ; WHEN COURSE, SHIP SPEED, APPARENT DIRECTION, AND WIND SPEED ; ARE ALL IN RANGE BUT ALL OF THESE INPUT VALUES ARE MISSING, ; THEN SET TRUE WIND DIRECTION AND SPEED TO MISSING. else : begin nwam = nwam + 1 tdir(i) = wmis(2) tspd(i) = wmis(3) end endcase endfor ; OUTPUT OPTION SELECTION FOR TRUEWIND.F case SEL of 1: BEGIN full, num, crse, cspd, wdir, zlr, hd, adir, wspd, tdir, tspd missing_values, num, crse, cspd, wdir, hd, wspd, tdir, tspd, wmis truerr, num, crse, cspd, hd, wdir, wspd, wmis, nw, nwpm, nwam, nwf END 2: BEGIN missing_values, num, crse, cspd, wdir, hd, wspd, tdir, tspd, wmis truerr, num, crse, cspd, hd, wdir, wspd, wmis, nw, nwpm, nwam, nwf END 3: truerr, num, crse, cspd, hd, wdir, wspd, wmis, nw, nwpm, nwam, nwf 4: BEGIN END ELSE: BEGIN PRINT, 'Selection invalid. Using selection #3 as default.' truerr, num, crse, cspd, hd, wdir, wspd, wmis, nw, nwpm, nwam, nwf END endcase end