au.csiro.netcdf.util
Class NetCDFUtils

java.lang.Object
  extended by au.csiro.netcdf.util.NetCDFUtils

public class NetCDFUtils
extends Object

A collection of netCDF specific utility functions. Copyright 2010, CSIRO Australia All rights reserved.

Version:
$Revision: 78 $ $Date: 2010-07-24 16:23:13 +1000 (Sat, 24 Jul 2010) $
Author:
James Dempsey on 22/03/2010

Field Summary
static int NOT_FOUND
          Index value to be returned when the value cannot be found in the array
static String NULL_VALUE
           
 
Constructor Summary
NetCDFUtils()
           
 
Method Summary
static int lookupIndex(NetcdfFile file, Dimension dimension, String value)
          Lookup the index of a value in a dimension.
static List<Attribute> mapStringToAttributeValueList(String commaSeparatedAttributeValueString)
          Converts a comma separated String into a String Attribute list.
static List<Attribute> mapStringToAttributeValueList(String commaSeparatedAttributeValueString, DataType dataType)
          Converts a comma separated String into an Attribute list.
static List<Attribute> readAttributesFromStream(InputStream input)
          Converts an input stream into an Attribute list.
static int searchCharArray(Array source, Character value)
          Search a netCDF Array containing character values stored in ascending order, i.e.
static int searchFloatingPointArray(Array source, double value, double tolerance)
          Search a netCDF Array containing floating point numeric values (double, float) stored in ascending order.
static int searchIntegralArray(Array source, long value)
          Search a netCDF Array containing integer numeric values (int, long, short, byte) stored in ascending order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_FOUND

public static final int NOT_FOUND
Index value to be returned when the value cannot be found in the array

See Also:
Constant Field Values

NULL_VALUE

public static final String NULL_VALUE
See Also:
Constant Field Values
Constructor Detail

NetCDFUtils

public NetCDFUtils()
Method Detail

lookupIndex

public static int lookupIndex(NetcdfFile file,
                              Dimension dimension,
                              String value)
                       throws IOException
Lookup the index of a value in a dimension. The dimension to be searched must have a coordinate variable (a variable with the same name as the dimension). A binary search is tried first for speed based on the common scenario that the corresponding variable contain numeric or string data stored in ascending order. If the binary search fails a scan of the variable is made for the value.

Parameters:
file - The NetCDF file being processed.
dimension - The dimension the value comes from
value - The value to be found
Returns:
The index of the item, or -1 if it cannot be found.
Throws:
IOException - If data cannot be read from the dimension

searchIntegralArray

public static int searchIntegralArray(Array source,
                                      long value)
Search a netCDF Array containing integer numeric values (int, long, short, byte) stored in ascending order.

Parameters:
source - The array to be searched
value - The value to be found
Returns:
The index of the value in the array, or -1 if not found.

searchFloatingPointArray

public static int searchFloatingPointArray(Array source,
                                           double value,
                                           double tolerance)
Search a netCDF Array containing floating point numeric values (double, float) stored in ascending order.

Parameters:
source - The array to be searched
value - The value to be found
tolerance - The comparison tolerance for floating point value comparisons
Returns:
The index of the value in the array, or -1 if not found.

searchCharArray

public static int searchCharArray(Array source,
                                  Character value)
Search a netCDF Array containing character values stored in ascending order, i.e. ascending unicode numeric values.

Parameters:
source - The array to be searched
value - The value to be found
Returns:
The index of the value in the array, or -1 if not found.

mapStringToAttributeValueList

public static List<Attribute> mapStringToAttributeValueList(String commaSeparatedAttributeValueString)
                                                     throws IllegalArgumentException
Converts a comma separated String into a String Attribute list.

Parameters:
commaSeparatedAttributeValueString - a list of comma separated attribute-value pairs, e.g. attribute1=value1,attribute2=value2,...
Returns:
an Attribute list.
Throws:
IllegalArgumentException - thrown if the String can not be converted into an Attribute list.

mapStringToAttributeValueList

public static List<Attribute> mapStringToAttributeValueList(String commaSeparatedAttributeValueString,
                                                            DataType dataType)
                                                     throws IllegalArgumentException
Converts a comma separated String into an Attribute list.

Parameters:
commaSeparatedAttributeValueString - a list of comma separated attribute-value pairs, e.g. attribute1=value1,attribute2=value2,...
dataType - The type of attributes to be created.
Returns:
an Attribute list.
Throws:
IllegalArgumentException - thrown if the String can not be converted into an Attribute list.

readAttributesFromStream

public static List<Attribute> readAttributesFromStream(InputStream input)
                                                throws IOException
Converts an input stream into an Attribute list.

Parameters:
input - the input stream
Returns:
an Attribute list.
Throws:
IOException


Copyright © 2010. All Rights Reserved.