Omaha #3583 productsrv no longer uses serialization util for JAXB
Change-Id: Ifad0e3cc6c875e66e695f7f812b038105ec64b18 Former-commit-id: e3dbeb01aa3235db1f6e72a41bdbcd456a60f37f
This commit is contained in:
parent
004bc1692a
commit
b984f9e3ed
9 changed files with 4 additions and 894 deletions
|
@ -1,7 +0,0 @@
|
|||
#Thu Mar 26 10:26:51 CDT 2009
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -7,6 +7,8 @@
|
|||
factory-method="getInstance" >
|
||||
<property name="maxSize" value="50" />
|
||||
</bean>
|
||||
|
||||
<bean id="jaxbMessageRegistry" class="com.raytheon.uf.common.message.JAXBMessageRegistry" factory-method="getInstance" />
|
||||
|
||||
<bean id="uEngine" class="com.raytheon.edex.services.ProductSrv" />
|
||||
|
||||
|
@ -28,7 +30,7 @@
|
|||
<from uri="ref:uEngineHttpJaxb_from" />
|
||||
<removeHeaders pattern="CamelHttp*" />
|
||||
<bean ref="uEngine" method="executePython" />
|
||||
<bean ref="serializationUtil" method="marshalToXml" />
|
||||
<bean ref="jaxbMessageRegistry" method="marshalToXml" />
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
|
|
@ -10,8 +10,7 @@ Export-Package: com.raytheon.edex.uengine,
|
|||
com.raytheon.edex.uengine.jep,
|
||||
com.raytheon.edex.uengine.runners,
|
||||
com.raytheon.edex.uengine.tasks,
|
||||
com.raytheon.edex.uengine.tasks.query,
|
||||
com.raytheon.edex.uengine.util
|
||||
com.raytheon.edex.uengine.tasks.query
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Import-Package: com.raytheon.edex.exception,
|
||||
com.raytheon.edex.msg,
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.uengine.tasks.process;
|
||||
|
||||
import com.raytheon.edex.uengine.tasks.ScriptTask;
|
||||
import com.raytheon.edex.uengine.util.JMath;
|
||||
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
||||
import com.raytheon.uf.common.datastorage.records.IDataRecord;
|
||||
|
||||
/**
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* 07Jun2007 TO6 MW Fegan Created.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mfegan
|
||||
* @version 1
|
||||
*/
|
||||
|
||||
public class ConvertWindsData extends ScriptTask {
|
||||
private boolean speed = true;
|
||||
|
||||
private IDataRecord uWinds = null;
|
||||
|
||||
private IDataRecord vWinds = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param uWinds
|
||||
* @param vWinds
|
||||
* @param speed
|
||||
*/
|
||||
public ConvertWindsData(IDataRecord uWinds, IDataRecord vWinds,
|
||||
boolean speed) {
|
||||
this.uWinds = uWinds;
|
||||
this.vWinds = vWinds;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.edex.uengine.tasks.ScriptTask#execute()
|
||||
*/
|
||||
@Override
|
||||
public Object execute() {
|
||||
FloatDataRecord retVal = null;
|
||||
if (!(uWinds instanceof FloatDataRecord)
|
||||
|| !(vWinds instanceof FloatDataRecord)) {
|
||||
return retVal;
|
||||
}
|
||||
JMath math = new JMath();
|
||||
float[] data;
|
||||
if (speed) {
|
||||
data = math.awndspd((float[]) uWinds.getDataObject(),
|
||||
(float[]) vWinds.getDataObject());
|
||||
} else {
|
||||
data = math.awnddir((float[]) uWinds.getDataObject(),
|
||||
(float[]) vWinds.getDataObject());
|
||||
}
|
||||
retVal = new FloatDataRecord(uWinds.getName(), "", data, uWinds
|
||||
.getDimension(), uWinds.getSizes());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.uengine.tasks.process;
|
||||
|
||||
import com.raytheon.edex.uengine.tasks.ScriptTask;
|
||||
import com.raytheon.edex.uengine.util.JMath;
|
||||
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
||||
import com.raytheon.uf.common.datastorage.records.IDataRecord;
|
||||
|
||||
/**TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mfegan
|
||||
* @version 1
|
||||
*/
|
||||
|
||||
public class StopLightImage extends ScriptTask {
|
||||
private IDataRecord dataRecord = null;
|
||||
private float red = (float)2.0;
|
||||
private float yellow = (float)1.0;
|
||||
private float green = (float)0.0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param dataRecord data record to be stop-lighted.
|
||||
*/
|
||||
public StopLightImage(IDataRecord dataRecord) {
|
||||
this.dataRecord = dataRecord;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.raytheon.edex.uengine.tasks.ScriptTask#execute()
|
||||
*/
|
||||
@Override
|
||||
public Object execute() {
|
||||
// TODO Auto-generated method stub
|
||||
JMath math = new JMath();
|
||||
if (!(dataRecord instanceof FloatDataRecord)) {
|
||||
return dataRecord;
|
||||
}
|
||||
float[] data = (float[]) dataRecord.getDataObject();
|
||||
float[] filtered = math.astoplight(data, this.red, this.yellow, this.green);
|
||||
((FloatDataRecord)dataRecord).setFloatData(filtered);
|
||||
return dataRecord;
|
||||
}
|
||||
public void setColors(float red, float yellow, float green) {
|
||||
this.red = red;
|
||||
this.yellow = yellow;
|
||||
this.green = green;
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.uengine.tasks.process;
|
||||
|
||||
import com.raytheon.edex.uengine.tasks.ScriptTask;
|
||||
|
||||
/**
|
||||
* Provides a simple logging capability for uEngine scripts, utilizing the
|
||||
* Apache Log4J facility. Logging is performed at the levels supported by
|
||||
* Log4J (debug, info, warn, error, fatal).
|
||||
* <BR>
|
||||
* <B>Note:</B> This class is intended for use within a JS uEngine script.
|
||||
* <BR>
|
||||
* <pre>
|
||||
* Usage:
|
||||
* function myFunc() {
|
||||
* var logger = new System Log();
|
||||
* logger.log("info","executing myFunc");
|
||||
* .
|
||||
* .
|
||||
* .
|
||||
* }
|
||||
* </pre>
|
||||
* @author mfegan
|
||||
* @version 1
|
||||
*/
|
||||
public class SystemLog extends ScriptTask {
|
||||
|
||||
private String level = "info";
|
||||
private String message = "";
|
||||
/**
|
||||
* Writes the message to the system log file at the specified level.
|
||||
*
|
||||
* @see ScriptTask#execute().
|
||||
*/
|
||||
@Override
|
||||
public Object execute() {
|
||||
if (level.equalsIgnoreCase("fatal")) {
|
||||
logger.fatal(message);
|
||||
} else if (level.equalsIgnoreCase("warn")) {
|
||||
logger.warn(message);
|
||||
} else if (level.equalsIgnoreCase("error")) {
|
||||
logger.error(message);
|
||||
} else if (level.equalsIgnoreCase("info")) {
|
||||
logger.info(message);
|
||||
} else {
|
||||
logger.debug(message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Writes a message to the system log. The message is logged at the specified
|
||||
* logging level. The message format depends on the system Log4J settings.
|
||||
* Messages level that are actually logged also depends on system Log4J configuration.
|
||||
*
|
||||
* @param level the logging level. One of "fatal", "error", "warn", "info", and "debug"
|
||||
* @param message the message to log.
|
||||
*/
|
||||
public void log(String level,String message) {
|
||||
this.level = level;
|
||||
this.message = message;
|
||||
execute();
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.raytheon.edex.uengine.util;
|
||||
|
||||
/**
|
||||
* Contains definitions of values defining the EDEX Cononical message. The basic
|
||||
* format of the cononical message is:
|
||||
* <pre>
|
||||
* {@literal <message> }
|
||||
* {@literal <header> }
|
||||
* {@literal <property name="id" value="<<identifier>>" /> }
|
||||
* {@literal <property name="time" value="<<date/time>>" /> }
|
||||
* {@literal <property name="function" value="<<function>>" /> }
|
||||
* {@literal </header> }
|
||||
* {@literal <body> }
|
||||
* {@literal <!-- contains the body of the message --> }
|
||||
* {@literal </body> }
|
||||
* {@literal </message> }
|
||||
* </PRE>
|
||||
* This class currently defines the valid values for the {@code function} property.
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date PR# Engineer Description
|
||||
* ----------- ---------- ------------ --------------------------
|
||||
* 10Aug2006 Task 19 MW Fegan Initial Creation
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author mfegan
|
||||
*
|
||||
*/
|
||||
public final class EdexMessage {
|
||||
/**
|
||||
* Function property value for validating the message body.
|
||||
*/
|
||||
public static final String VALIDATE = "validate";
|
||||
/**
|
||||
* Function property value for executing the message body.
|
||||
*/
|
||||
public static final String EXECUTE = "execute";
|
||||
/**
|
||||
* Function property value for subscribing the message body.
|
||||
*/
|
||||
public static final String SUBSCRIBE = "subscribe";
|
||||
/**
|
||||
* Function property value for unsubscribing the message body.
|
||||
*/
|
||||
public static final String UNSUBSCRIBE = "unsubscribe";
|
||||
/**
|
||||
* Function property value indicating the message body is a response.
|
||||
*/
|
||||
public static final String RESPONSE = "response";
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.uengine.util;
|
||||
|
||||
/**
|
||||
* Contains mathematics routines intended primarily for GRIB record manipulations.
|
||||
* This class is intended to support the μEngine's Jython scripting tags.
|
||||
* <P>
|
||||
* <b>Usage:</B>
|
||||
* <PRE>
|
||||
* {@literal <mathScript using="gribout">}
|
||||
* {@literal <input name="u" value="uwind" />}
|
||||
* {@literal <input name="v" value="vwind" />}
|
||||
* {@literal <param name="red" value="2.0" />}
|
||||
* {@literal <param name="yellow" value="1.0" />}
|
||||
* {@literal <param name="green" value="0.0" />}
|
||||
* {@literal <![CDATA[}
|
||||
* {@literal import com.raytheon.edex.uengine.util.jython as utilities}
|
||||
* {@literal utils = utilities.JMath()}
|
||||
* {@literal STDOUT = utils.awndspd(u,v)}
|
||||
* {@literal STDOUT = utils.astoplight(STDOUT,red,yellow,green)}
|
||||
* {@literal ]]>}
|
||||
* {@literal </mathScript>}
|
||||
* </PRE>
|
||||
* This is an example of using the {@code <mathScript />} μEngine task to
|
||||
* perform a wind speed analysis on previously retrieved grib records and then
|
||||
* producing a red, yellow, green stop light chart from the wind speeds.
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* 06Nov2006 TO4 MW Fegan Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mfegan
|
||||
* @version 1
|
||||
*/
|
||||
|
||||
public class JMath {
|
||||
|
||||
/*
|
||||
* constants.
|
||||
*/
|
||||
private static final float NULL = (float)9999;
|
||||
|
||||
/**
|
||||
* Contructor.
|
||||
*
|
||||
*/
|
||||
public JMath() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Converts a grid to a stoplight chart. This is a demo function that uses
|
||||
* a decile based formula for the coloring.
|
||||
* <PRE>
|
||||
* {@literal decile 0 1 2 3 4 5 6 7 8 9}
|
||||
* {@literal color red yellow green green green green green green yellow red}
|
||||
* </PRE>
|
||||
* @param data GRIB record to be used for the chart.
|
||||
* @param red grib value for "red"
|
||||
* @param yellow grib value for "yellow"
|
||||
* @param green grib value for "green"
|
||||
*
|
||||
* @return the transformed grib record.
|
||||
*/
|
||||
public float[] astoplight(float[] data,
|
||||
float red,
|
||||
float yellow,
|
||||
float green) {
|
||||
return astoplight(data,red,yellow,green,yellow,red);
|
||||
}
|
||||
/**
|
||||
* Converts a grid to a stoplight chart. This is a demo function that uses
|
||||
* a decile based formula for the coloring.
|
||||
* <PRE>
|
||||
* {@literal decile 0 1 2 3 4 5 6 7 8 9}
|
||||
* {@literal region I II III III III III III III IV V}
|
||||
* </PRE>
|
||||
*
|
||||
* @param data GRIB record to be used for the chart.
|
||||
* @param clr0 new grib value for region I
|
||||
* @param clr1 new grib value for region II
|
||||
* @param clr2 new grib value for region III
|
||||
* @param clr3 new grib value for region IV
|
||||
* @param clr4 new grib value for region V
|
||||
*
|
||||
* @return the transformed grib record.
|
||||
*/
|
||||
public float[] astoplight(float[] data,
|
||||
float clr0,
|
||||
float clr1,
|
||||
float clr2,
|
||||
float clr3,
|
||||
float clr4) {
|
||||
float min = amin(data);
|
||||
float max = amax(data);
|
||||
float rng = max - min;
|
||||
float p = rng / (float)10.0;
|
||||
float p1 = min + p;
|
||||
float p2 = p1 + p;
|
||||
float p3 = p2 + (float)6 * p;
|
||||
float p4 = p3 + p;
|
||||
float[] retVal = new float[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
float z = data[i];
|
||||
if (z == NULL) {
|
||||
retVal[i] = clr0;
|
||||
} else if (z < p1) {
|
||||
retVal[i] = clr0;
|
||||
} else if (z < p2) {
|
||||
retVal[i] = clr1;
|
||||
} else if (z < p3) {
|
||||
retVal[i] = clr2;
|
||||
} else if (z < p4) {
|
||||
retVal[i] = clr3;
|
||||
} else {
|
||||
retVal[i] = clr4;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
|
||||
}
|
||||
/**
|
||||
* Creates a {@code float[]} by taking the maximum value of corresponding elements
|
||||
* of the two {@code float[]} input array. That is, c<sub>i</sub> = max(a<sub>i</sub>,
|
||||
* b<sub>i</sub>).
|
||||
*
|
||||
* @param a the first array.
|
||||
* @param b the recond array.
|
||||
*
|
||||
* @return the max array.
|
||||
*/
|
||||
public float[] amax(float[] a, float[] b) {
|
||||
if(a.length != b.length) {
|
||||
return (float[])null;
|
||||
}
|
||||
float[] retVal = new float[a.length];
|
||||
for (int i = 0; i < a.length;i++) {
|
||||
retVal[i] = Math.max(a[i], b[i]);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* Creates an {@code int[]} by taking the maximum value of corresponding elements
|
||||
* of the two {@code int[]} input array. That is, c<sub>i</sub> = max(a<sub>i</sub>,
|
||||
* b<sub>i</sub>).
|
||||
*
|
||||
* @param a the first array.
|
||||
* @param b the recond array.
|
||||
*
|
||||
* @return the max array.
|
||||
*/
|
||||
public int[] amax(int[] a, int[] b) {
|
||||
if(a.length != b.length) {
|
||||
return (int[])null;
|
||||
}
|
||||
int[] retVal = new int[a.length];
|
||||
for (int i = 0; i < a.length;i++) {
|
||||
retVal[i] = Math.max(a[i], b[i]);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* Creates a {@code float[]} by taking the average of the correcponding elements of
|
||||
* the two {@code float[]} inputs. That is, c<sub>i</sub> = (a<sub>i</sub> +
|
||||
* b<sub>i</sub>) / 2.0.
|
||||
*
|
||||
* @param a the first array.
|
||||
* @param b the recond array.
|
||||
*
|
||||
* @return the mean array.
|
||||
*/
|
||||
public float[] amean(float[] a, float[] b) {
|
||||
if(a.length != b.length) {
|
||||
return (float[])null;
|
||||
}
|
||||
float[] retVal = new float[a.length];
|
||||
for (int i = 0; i < a.length;i++) {
|
||||
retVal[i] = (a[i] + b[i]) / (float)2;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* Creates an {@code int[]} by taking the average of the corresponding elements of
|
||||
* the two {@code int[]} inputs. That is, c<sub>i</sub> = (a<sub>i</sub> +
|
||||
* b<sub>i</sub>) / 2.
|
||||
*
|
||||
* @param a the first array.
|
||||
* @param b the recond array.
|
||||
*
|
||||
* @return the mean array.
|
||||
*/
|
||||
public int[] amean(int[] a, int[] b) {
|
||||
if(a.length != b.length) {
|
||||
return (int[])null;
|
||||
}
|
||||
int[] retVal = new int[a.length];
|
||||
for (int i = 0; i < a.length;i++) {
|
||||
retVal[i] = (a[i] + b[i]) / 2;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* Performs the wind speed computation for a pair of wind-u, wind-v buffers.
|
||||
*
|
||||
* @param u the wind-u buffer.
|
||||
* @param v the wind-v buffer.
|
||||
*
|
||||
* @return a buffer containing the wind speeds.
|
||||
*/
|
||||
public float[] awndspd(float[] u, float[] v) {
|
||||
if(u.length != v.length) {
|
||||
return (float[])null;
|
||||
}
|
||||
float[] retVal = new float[u.length];
|
||||
for (int i = 0; i < u.length; i++) {
|
||||
Vector vector = new Vector(Vector.VECTOR_UV,u[i],v[i]);
|
||||
retVal[i] = vector.getMagnitude();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* Performs the wind direction computation for a pair of wind-u, wind-v buffers.
|
||||
*
|
||||
* @param u the wind-u buffer.
|
||||
* @param v the wind-v buffer.
|
||||
*
|
||||
* @return a buffer containing the wind speeds.
|
||||
*/
|
||||
public float[] awnddir(float[] u, float[] v) {
|
||||
if(u.length != v.length) {
|
||||
return (float[])null;
|
||||
}
|
||||
float[] retVal = new float[u.length];
|
||||
for (int i = 0; i < u.length; i++) {
|
||||
Vector vector = new Vector(Vector.VECTOR_UV,u[i],v[i]);
|
||||
retVal[i] = vector.getDirection();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* finds the minimum value of a {@code float[]} array.
|
||||
*
|
||||
* @param a the buffer containing the values to process.
|
||||
*
|
||||
* @return the minimum.
|
||||
*/
|
||||
public float amin(float[] a) {
|
||||
float retVal = a[0];
|
||||
for (float f : a) {
|
||||
if(f < retVal) {
|
||||
retVal = f;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* finds the minimum value of a {@code int[]} array.
|
||||
*
|
||||
* @param a the buffer containing the values to process.
|
||||
*
|
||||
* @return the minimum.
|
||||
*/
|
||||
public int amin(int[] a) {
|
||||
int retVal = a[0];
|
||||
for (int f : a) {
|
||||
if(f < retVal) {
|
||||
retVal = f;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* finds the maximum value of a {@code float[]} array.
|
||||
*
|
||||
* @param a the buffer containing the values to process.
|
||||
*
|
||||
* @return the maximum.
|
||||
*/
|
||||
public float amax(float[] a) {
|
||||
float retVal = a[0];
|
||||
for (float f : a) {
|
||||
if(f > retVal) {
|
||||
retVal = f;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
/**
|
||||
* finds the maximum value of a {@code int[]} array.
|
||||
*
|
||||
* @param a the buffer containing the values to process.
|
||||
*
|
||||
* @return the maximum.
|
||||
*/
|
||||
public int amax(int[] a) {
|
||||
int retVal = a[0];
|
||||
for (int f : a) {
|
||||
if(f > retVal) {
|
||||
retVal = f;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
|
@ -1,235 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
package com.raytheon.edex.uengine.util;
|
||||
|
||||
/**
|
||||
* Represents a two dimensional vector.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* 10Nov2006 TO4 MW Fegan Iniitial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mfegan
|
||||
* @version 1
|
||||
*/
|
||||
|
||||
public class Vector {
|
||||
/**
|
||||
* Initialization constant. Indicates the vector is being initialized using
|
||||
* U,V coordinates
|
||||
*/
|
||||
public static final int VECTOR_UV = 0;
|
||||
/**
|
||||
* Initialization constant. Indicated the vector is being initialized using
|
||||
* ρ,θ (rho,theta) coordinates.
|
||||
*/
|
||||
public static final int VECTOR_RT = 1;
|
||||
/*
|
||||
* the vector components
|
||||
*/
|
||||
private float vectorU = 0;
|
||||
private float vectorV = 0;
|
||||
private float vectorRho = 0;
|
||||
private float vectorTheta = 0;
|
||||
|
||||
/*
|
||||
* constants for vector resolution
|
||||
*/
|
||||
private static final double RDNTODEG = 57.2957795;
|
||||
private static final double DEG_HALF_PI = 180.0;
|
||||
private static final double R_EQ_ZERO = 1.0E-10;
|
||||
|
||||
/**
|
||||
* Constructor. Creates a vector from the specified coordinates. The coorinate
|
||||
* system, rectangular or polar, is determined by the {@code system} argument.
|
||||
*
|
||||
* @param system determines the coordinate system of the vector. Allowed values
|
||||
* are {@link #VECTOR_RT} or {@link #VECTOR_UV}.
|
||||
* @param abscissa the first coordinate (U or ρ)
|
||||
* @param ordinate the second coordinate (V or &theta)
|
||||
*/
|
||||
public Vector(int system, float abscissa, float ordinate) {
|
||||
createVector(system,abscissa, ordinate);
|
||||
}
|
||||
/**
|
||||
* Constructor. Creates a vector from the specified coordinates. The vector is
|
||||
* assumed to be in rectangular coordinates.
|
||||
*
|
||||
* @param abscissa the first coordinate
|
||||
* @param ordinate the second coordinate
|
||||
*/
|
||||
public Vector (float abscissa, float ordinate) {
|
||||
createVector(VECTOR_UV,abscissa, ordinate);
|
||||
}
|
||||
/**
|
||||
* Resolves the vector using the specified coordinate system.
|
||||
*
|
||||
* @param system determines the coordinate system for resolving the vector.
|
||||
* Allowed values are {@link #VECTOR_RT} or {@link #VECTOR_UV}.
|
||||
*/
|
||||
public void resolve(int system) {
|
||||
if(system == VECTOR_UV) {
|
||||
resolveUV();
|
||||
} else if (system == VECTOR_RT) {
|
||||
resolveRT();
|
||||
} else {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Resets the vector to the initial state. All components are set to {@code (float)0}.
|
||||
*
|
||||
*/
|
||||
public void clear() {
|
||||
vectorRho = (float)0;
|
||||
vectorTheta = (float)0;
|
||||
vectorU = (float)0;
|
||||
vectorV = (float)0;
|
||||
}
|
||||
/*
|
||||
* helper methods
|
||||
*/
|
||||
/**
|
||||
* Populates the vector. Missing components are computed from the coordinates provided.
|
||||
*
|
||||
* @param system system flag. Must be{@link #VECTOR_RT} or {@link #VECTOR_UV}.
|
||||
* @param abscissa the first coordinate (ρ or U)
|
||||
* @param ordinate the first coordinate (θ or V)
|
||||
*/
|
||||
private void createVector(int system, float abscissa, float ordinate) {
|
||||
if (system == VECTOR_UV) {
|
||||
vectorU = abscissa;
|
||||
vectorV = ordinate;
|
||||
resolveUV();
|
||||
} else if (system == VECTOR_RT) {
|
||||
vectorRho = abscissa;
|
||||
vectorTheta = ordinate;
|
||||
resolveRT();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Resolves the vector when U,V coordinates have been set. The ρ and θ
|
||||
* coordinates are set as a result.
|
||||
*/
|
||||
private void resolveUV() {
|
||||
this.vectorRho = magnitude(this.vectorU,this.vectorV);
|
||||
this.vectorTheta = direction(this.vectorU,this.vectorV);
|
||||
}
|
||||
/**
|
||||
* Resolves the vector when ρ,θ coordinates have been set. The U and V
|
||||
* coordinates are set as a result.
|
||||
*
|
||||
*/
|
||||
private void resolveRT() {
|
||||
this.vectorU = this.vectorRho * (float)Math.cos((double)this.vectorTheta);
|
||||
this.vectorV = this.vectorRho * (float)Math.sin((double)this.vectorTheta);
|
||||
}
|
||||
/**
|
||||
* Comuptes the magnitude of the specified vector.
|
||||
*
|
||||
* @param u the "horizontal" component.
|
||||
* @param v the "vertical" component.
|
||||
*
|
||||
* @return the magnitude of the vector.
|
||||
*/
|
||||
private float magnitude(float u, float v) {
|
||||
return (float)Math.sqrt(u * u + v * v);
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the direction of the specified vector. The direction is returned
|
||||
* as degrees on the interval 0 ≤ direction ≤ 360.
|
||||
*
|
||||
* @param u the "horizontal" component.
|
||||
* @param v the "vertical" component.
|
||||
*
|
||||
* @return the direction
|
||||
*/
|
||||
private float direction(float u, float v) {
|
||||
float xspd = (float)Math.sqrt(u * u + v * v);
|
||||
float dir;
|
||||
if (xspd < R_EQ_ZERO) {
|
||||
dir = (float)0.0;
|
||||
} else {
|
||||
dir = (float)(Math.atan2(u, v) * RDNTODEG + DEG_HALF_PI + 1.0E-3) ;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
/*
|
||||
* Accessors
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return the vector magnitude
|
||||
*/
|
||||
public float getMagnitude() {
|
||||
return vectorRho;
|
||||
}
|
||||
/**
|
||||
* @param magnitude the magnitude to set
|
||||
*/
|
||||
public void setMagnitude(float magnitude) {
|
||||
this.vectorRho = magnitude;
|
||||
}
|
||||
/**
|
||||
* @return the vector direction
|
||||
*/
|
||||
public float getDirection() {
|
||||
return vectorTheta;
|
||||
}
|
||||
/**
|
||||
* @param direction the vector direction to set
|
||||
*/
|
||||
public void setDirection(float direction) {
|
||||
this.vectorTheta = direction;
|
||||
}
|
||||
/**
|
||||
* @return the vectorU
|
||||
*/
|
||||
public float getVectorU() {
|
||||
return vectorU;
|
||||
}
|
||||
/**
|
||||
* @param vectorU the vectorU to set
|
||||
*/
|
||||
public void setVectorU(float vectorU) {
|
||||
this.vectorU = vectorU;
|
||||
}
|
||||
/**
|
||||
* @return the vectorV
|
||||
*/
|
||||
public float getVectorV() {
|
||||
return vectorV;
|
||||
}
|
||||
/**
|
||||
* @param vectorV the vectorV to set
|
||||
*/
|
||||
public void setVectorV(float vectorV) {
|
||||
this.vectorV = vectorV;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue