ucar.unidata.data
Class DataUtil

java.lang.Object
  extended by ucar.unidata.data.DataUtil

public class DataUtil
extends Object

A class to hold general utility functions for manipulating data

Version:
$Revision: 1.8 $
Author:
IDV development team

Field Summary
static String STD_ATMOSPHERE
          flag for standard atmosphere coordinate system class
static String VIS5D_VERTICALCS
          flag for Vis5D pressure to height coordinate system class
 
Constructor Summary
DataUtil()
           
 
Method Summary
static void absoluteValue(float[][] originalValues, float[][] newValues, int[] indexArray)
          copy the originalValues to the new values.
static void average(float[][] originalValues, float[][] newValues, int[] indexArray)
          set newValues to be the average of the original values in the index array
static String cleanName(String name)
          Make a valid VisAD RealType name from the string.
static float[][] cloneArray(float[][] a)
          clone the array
static FlatField getFlatField(Data field)
          This method find the flat field somewhere in the given data
static CoordinateSystem getPressureToHeightCS(String type)
          Get the appropriate vertical coordinate system
static float[][] makeFloatArray(int rows, int cols, float value)
          Make a float array of the sizes indicated with the value
static RealType makeRealType(String name, Unit unit)
          Try to create a RealType from the name and unit.
static TextType makeTextType(String name)
          Try to create a TextType from the name.
static void max(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
          Copy the values in originalValues[indexArray] that are greater than the given value to newValues
static void min(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
          If the originalValues < given value then set the newValues = value
static Unit parseUnit(String unitString)
          Tries to parse the string.
static boolean pointInside(float[][] pts, float x, float y)
          Determine if the given point is inside the given polygon Code originally taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Copyright (c) 1970-2003, Wm.
static List<Date> selectDatesFromList(List sourceTimes, List<DateTime> driverTimes)
          _more_
static List<DateTime> selectTimesFromList(List sourceTimes, List<DateTime> selectionTimes)
          _more_
static void setValue(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
          set the values in the indices in newValues = the given value
static char[] toCharArray(ucar.ma2.Array arr)
          Get the 1D values for an array as chars.
static double[] toDoubleArray(ucar.ma2.Array arr)
          Get the 1D values for an array as doubles.
static float[] toFloatArray(ucar.ma2.Array arr)
          Get the 1D values for an array as floats.
static String[] toStringArray(ucar.ma2.Array arr)
          Get the 1D values for an array as Strings.
static void writeCsv(String filename, List rows)
          Write a csv file.
static void writeXls(String filename, List rows)
          Write to an excel spreadsheet
static void writeXls(String filename, List<List> rowsList, List<String> names)
          Write to an excel spreadsheet
static String xlsToCsv(String filename)
          Convert excel to csv
static String xlsToCsv(String filename, boolean skipToFirstNumeric, SimpleDateFormat sdf)
          Convert excel to csv
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STD_ATMOSPHERE

public static final String STD_ATMOSPHERE
flag for standard atmosphere coordinate system class

See Also:
Constant Field Values

VIS5D_VERTICALCS

public static final String VIS5D_VERTICALCS
flag for Vis5D pressure to height coordinate system class

See Also:
Constant Field Values
Constructor Detail

DataUtil

public DataUtil()
Method Detail

toFloatArray

public static float[] toFloatArray(ucar.ma2.Array arr)
Get the 1D values for an array as floats.

Parameters:
arr - Array of values
Returns:
float representation

toDoubleArray

public static double[] toDoubleArray(ucar.ma2.Array arr)
Get the 1D values for an array as doubles.

Parameters:
arr - Array of values
Returns:
double representation

toStringArray

public static String[] toStringArray(ucar.ma2.Array arr)
Get the 1D values for an array as Strings.

Parameters:
arr - Array of values
Returns:
String representation

toCharArray

public static char[] toCharArray(ucar.ma2.Array arr)
Get the 1D values for an array as chars.

Parameters:
arr - Array of values
Returns:
chars representation

parseUnit

public static Unit parseUnit(String unitString)
Tries to parse the string. If an exception occurs just return null.

Parameters:
unitString - The unit string
Returns:
The parsed unit or null if an error occurs

makeTextType

public static TextType makeTextType(String name)
Try to create a TextType from the name.

Parameters:
name - name of type
Returns:
TextType or null

makeRealType

public static RealType makeRealType(String name,
                                    Unit unit)
Try to create a RealType from the name and unit.

Parameters:
name - name of type
unit - can be null
Returns:
RealType or null

cleanName

public static String cleanName(String name)
Make a valid VisAD RealType name from the string. Remove spaces, "." and parens.

Parameters:
name - name to clean
Returns:
cleaned up name

getPressureToHeightCS

public static CoordinateSystem getPressureToHeightCS(String type)
                                              throws VisADException
Get the appropriate vertical coordinate system

Parameters:
type - type of pressure to height cs
Returns:
the corresponding CS
Throws:
VisADException - couldn't create the CS

makeFloatArray

public static float[][] makeFloatArray(int rows,
                                       int cols,
                                       float value)
Make a float array of the sizes indicated with the value

Parameters:
rows - number of arrays
cols - number of values in each row
value - fill value
Returns:
the filled in array

cloneArray

public static float[][] cloneArray(float[][] a)
clone the array

Parameters:
a - incoming array
Returns:
cloned array

absoluteValue

public static void absoluteValue(float[][] originalValues,
                                 float[][] newValues,
                                 int[] indexArray)
copy the originalValues to the new values. Set all values to be positive

Parameters:
originalValues - original values
newValues - new values
indexArray - The indices to change

max

public static void max(float[][] originalValues,
                       float[][] newValues,
                       int[] indexArray,
                       float value)
Copy the values in originalValues[indexArray] that are greater than the given value to newValues

Parameters:
originalValues - original values
newValues - new Values
indexArray - indices
value - the threshold value

setValue

public static void setValue(float[][] originalValues,
                            float[][] newValues,
                            int[] indexArray,
                            float value)
set the values in the indices in newValues = the given value

Parameters:
originalValues - originalValues
newValues - newValues
indexArray - indices
value - value

min

public static void min(float[][] originalValues,
                       float[][] newValues,
                       int[] indexArray,
                       float value)
If the originalValues < given value then set the newValues = value

Parameters:
originalValues - originalValues
newValues - newValues
indexArray - indices
value - value

average

public static void average(float[][] originalValues,
                           float[][] newValues,
                           int[] indexArray)
set newValues to be the average of the original values in the index array

Parameters:
originalValues - original values
newValues - new value
indexArray - indices

getFlatField

public static FlatField getFlatField(Data field)
                              throws VisADException,
                                     RemoteException
This method find the flat field somewhere in the given data

Parameters:
field - field
Returns:
a flat field or null
Throws:
RemoteException - on badness
VisADException - on badness

writeCsv

public static void writeCsv(String filename,
                            List rows)
Write a csv file. The rows list contains lists. We take the toString value of each list element

Parameters:
filename - file to write to
rows - data

writeXls

public static void writeXls(String filename,
                            List rows)
                     throws Exception
Write to an excel spreadsheet

Parameters:
filename - file
rows - data
Throws:
Exception - On badness

writeXls

public static void writeXls(String filename,
                            List<List> rowsList,
                            List<String> names)
                     throws Exception
Write to an excel spreadsheet

Parameters:
filename - file
rowsList - data
names - sheet names
Throws:
Exception - On badness

xlsToCsv

public static String xlsToCsv(String filename)
                       throws Exception
Convert excel to csv

Parameters:
filename - excel file
Returns:
csv
Throws:
Exception - On badness

xlsToCsv

public static String xlsToCsv(String filename,
                              boolean skipToFirstNumeric,
                              SimpleDateFormat sdf)
                       throws Exception
Convert excel to csv

Parameters:
filename - excel file
skipToFirstNumeric - _more_
sdf - If non null then use this to format any date cells
Returns:
csv
Throws:
Exception - On badness

pointInside

public static boolean pointInside(float[][] pts,
                                  float x,
                                  float y)
Determine if the given point is inside the given polygon Code originally taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Copyright (c) 1970-2003, Wm. Randolph Franklin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. 2. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution. 3. The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Parameters:
pts - _more_
x - _more_
y - _more_
Returns:
_more_

selectDatesFromList

public static List<Date> selectDatesFromList(List sourceTimes,
                                             List<DateTime> driverTimes)
                                      throws Exception
_more_

Parameters:
sourceTimes - _more_
driverTimes - _more_
Returns:
_more_
Throws:
Exception - _more_

selectTimesFromList

public static List<DateTime> selectTimesFromList(List sourceTimes,
                                                 List<DateTime> selectionTimes)
                                          throws Exception
_more_

Parameters:
sourceTimes - _more_
selectionTimes - _more_
Returns:
_more_
Throws:
Exception - _more_