loci.formats.services

## Class NetCDFServiceImpl

- java.lang.Object
- - loci.common.services.AbstractService
  - - loci.formats.services.NetCDFServiceImpl

- All Implemented Interfaces:
    com.esotericsoftware.kryo.KryoSerializable, loci.common.services.Service, NetCDFService

      public class NetCDFServiceImpl
      extends loci.common.services.AbstractService
      implements NetCDFService, com.esotericsoftware.kryo.KryoSerializable

  Utility class for working with NetCDF/HDF files. Uses reflection to call the NetCDF Java library.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.util.Vector<java.lang.String>` | `attributeList`
    `private java.lang.String` | `currentFile`
    `private ucar.nc2.NetcdfFile` | `netCDFFile` NetCDF file instance.
    `static java.lang.String` | `NO_NETCDF_MSG`
    `private ucar.unidata.io.RandomAccessFile` | `raf`
    `private ucar.nc2.Group` | `root` Root of the NetCDF file.
    `private java.util.Vector<java.lang.String>` | `variableList`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NetCDFServiceImpl()` Default constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private java.lang.String` | `arrayToString(ucar.ma2.Array values)`
    `void` | `close()` Closes and resets the service.
    `java.lang.Object` | `getArray(java.lang.String path, int[] origin, int[] shape)` Retrieves an HDF path's values.
    `java.util.Vector<java.lang.String>` | `getAttributeList()` Retrieves an exhaustive list of the HDF paths for all attributes in the HDF document.
    `java.lang.String` | `getAttributeValue(java.lang.String path)` Retrieves an attribute's value.
    `int` | `getDimension(java.lang.String name)` Retrieves the length of a dimension.
    `private java.lang.String` | `getDirectory(java.lang.String path)`
    `java.lang.String` | `getFile()` Retrieves the current initialized file path.
    `private ucar.nc2.Group` | `getGroup(java.lang.String path)` Retrieves a group based on its fully qualified path.
    `private java.lang.String` | `getName(java.lang.String path)`
    `java.util.Hashtable<java.lang.String,java.lang.Object>` | `getVariableAttributes(java.lang.String name)` Retrieves all of a variable's attributes.
    `java.util.Vector<java.lang.String>` | `getVariableList()` Retrieves an exhaustive list of the HDF paths for all variables in the HDF document.
    `java.lang.Object` | `getVariableValue(java.lang.String name)` Retrieves a variable's value.
    `private void` | `init()`
    `private void` | `parseAttributesAndVariables(java.util.List<ucar.nc2.Group> groups)` Recursively parses attribute and variable paths, filling `attributeList` and `variableList`.
    `void` | `read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input in)`
    `void` | `setFile(java.lang.String file)` Initializes the service on a given file path.
    `void` | `write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output out)`

    - ### Methods inherited from class loci.common.services.AbstractService

      `checkClassDependency`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NO_NETCDF_MSG

          public static final java.lang.String NO_NETCDF_MSG

    - #### currentFile

          private java.lang.String currentFile

    - #### attributeList

          private java.util.Vector<java.lang.String> attributeList

    - #### variableList

          private java.util.Vector<java.lang.String> variableList

    - #### netCDFFile

          private ucar.nc2.NetcdfFile netCDFFile

      NetCDF file instance.

    - #### raf

          private ucar.unidata.io.RandomAccessFile raf

    - #### root

          private ucar.nc2.Group root

      Root of the NetCDF file.

  - ### Constructor Detail

    - #### NetCDFServiceImpl

          public NetCDFServiceImpl()

      Default constructor.

  - ### Method Detail

    - #### setFile

          public void setFile(java.lang.String file)
                       throws java.io.IOException

      Description copied from interface: `NetCDFService`
      Initializes the service on a given file path.
      Specified by:
        `setFile` in interface `NetCDFService`
      Parameters:
        `file` - Path to initialize the service with.
      Throws:
        `java.io.IOException` - If there is an error initializing the service with `file`.

    - #### getFile

          public java.lang.String getFile()

      Description copied from interface: `NetCDFService`
      Retrieves the current initialized file path.
      Specified by:
        `getFile` in interface `NetCDFService`
      Returns:
        Current initialized file path or `null` if the service has yet to be initialized or is closed.

    - #### getAttributeList

          public java.util.Vector<java.lang.String> getAttributeList()

      Description copied from interface: `NetCDFService`
      Retrieves an exhaustive list of the HDF paths for all attributes in the HDF document.
      Specified by:
        `getAttributeList` in interface `NetCDFService`
      Returns:
        Collection of attribute paths.

    - #### getVariableList

          public java.util.Vector<java.lang.String> getVariableList()

      Description copied from interface: `NetCDFService`
      Retrieves an exhaustive list of the HDF paths for all variables in the HDF document.
      Specified by:
        `getVariableList` in interface `NetCDFService`
      Returns:
        Collection of variable paths.

    - #### getAttributeValue

          public java.lang.String getAttributeValue(java.lang.String path)

      Description copied from interface: `NetCDFService`
      Retrieves an attribute's value.
      Specified by:
        `getAttributeValue` in interface `NetCDFService`
      Parameters:
        `path` - HDF path to the attribute.
      Returns:
        String value or `null` if the attribute is not a string.

    - #### getVariableValue

          public java.lang.Object getVariableValue(java.lang.String name)
                                            throws loci.common.services.ServiceException

      Description copied from interface: `NetCDFService`
      Retrieves a variable's value.
      Specified by:
        `getVariableValue` in interface `NetCDFService`
      Parameters:
        `name` - HDF path to the variable.
      Returns:
        The Java one-dimensional array representation of the variable's values.
      Throws:
        `loci.common.services.ServiceException` - If there is an error with the range of values or reading from the file.
      See Also:
        `Array.copyTo1DJavaArray()`

    - #### getArray

          public java.lang.Object getArray(java.lang.String path,
                                           int[] origin,
                                           int[] shape)
                                    throws loci.common.services.ServiceException

      Description copied from interface: `NetCDFService`
      Retrieves an HDF path's values.
      Specified by:
        `getArray` in interface `NetCDFService`
      Parameters:
        `path` - HDF path to the values.
        `origin` - Array specifying the starting index. If null, assume all zeroes.
        `shape` - Array specifying the extents in each dimension. This becomes the shape of the returned Array.
      Returns:
        The Java n-dimensional array representation of the path's values.
      Throws:
        `loci.common.services.ServiceException` - If there is an error with the range of values or reading from the file.
      See Also:
        `Variable.read(int[], int[])`, `Array.copyToNDJavaArray()`

    - #### getVariableAttributes

          public java.util.Hashtable<java.lang.String,java.lang.Object> getVariableAttributes(java.lang.String name)

      Description copied from interface: `NetCDFService`
      Retrieves all of a variable's attributes.
      Specified by:
        `getVariableAttributes` in interface `NetCDFService`
      Parameters:
        `name` - HDF path to the variable.
      Returns:
        Hash table of attributes to Java one-dimensional array representations of the attribute's values.
      See Also:
        `Array.copyTo1DJavaArray()`

    - #### getDimension

          public int getDimension(java.lang.String name)

      Description copied from interface: `NetCDFService`
      Retrieves the length of a dimension.
      Specified by:
        `getDimension` in interface `NetCDFService`
      Parameters:
        `name` - HDF path to the dimension.
      Returns:
        Length of the dimension.

    - #### close

          public void close()
                     throws java.io.IOException

      Description copied from interface: `NetCDFService`
      Closes and resets the service.
      Specified by:
        `close` in interface `NetCDFService`
      Throws:
        `java.io.IOException` - If there is an error closing the file.

    - #### parseAttributesAndVariables

          private void parseAttributesAndVariables(java.util.List<ucar.nc2.Group> groups)

      Recursively parses attribute and variable paths, filling `attributeList` and `variableList`.
      Parameters:
        `groups` - List of groups to recursively parse.

    - #### getGroup

          private ucar.nc2.Group getGroup(java.lang.String path)

      Retrieves a group based on its fully qualified path.
      Parameters:
        `path` - Fully qualified path to the group.
      Returns:
        Group or `root` if the group cannot be found.

    - #### getDirectory

          private java.lang.String getDirectory(java.lang.String path)

    - #### getName

          private java.lang.String getName(java.lang.String path)

    - #### arrayToString

          private java.lang.String arrayToString(ucar.ma2.Array values)

    - #### init

          private void init()
                     throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### read

          public void read(com.esotericsoftware.kryo.Kryo kryo,
                           com.esotericsoftware.kryo.io.Input in)

      Specified by:
        `read` in interface `com.esotericsoftware.kryo.KryoSerializable`

    - #### write

          public void write(com.esotericsoftware.kryo.Kryo kryo,
                            com.esotericsoftware.kryo.io.Output out)

      Specified by:
        `write` in interface `com.esotericsoftware.kryo.KryoSerializable`

Copyright © 2026 Open Microscopy Environment