Package ucar.nc2

Class NetcdfFile

java.lang.Object
ucar.nc2.NetcdfFile
All Implemented Interfaces:
Closeable, AutoCloseable, ucar.nc2.util.cache.FileCacheable
Direct Known Subclasses:
NetcdfDataset, NetcdfFileSubclass

public class NetcdfFile extends Object implements ucar.nc2.util.cache.FileCacheable, Closeable

Read-only scientific datasets that are accessible through the netCDF API. Immutable after setImmutable() is called. Reading data is not thread-safe because of the use of RandomAccessFile.

Using this class's Builder scheme to create a NetcdfFile object could, for example, be accomplished as follows, using a try/finally block to ensure that the NetcdfFile is closed when done.

 NetcdfFile ncfile = null;
 try {
   ncfile = NetcdfFile.builder().setLocation(fileName).build();
   // do stuff
 } finally {
   if (ncfile != null) {
     ncfile.close();
   }
 }
 
More conveniently, a NetcdfFile object may be created using one of the static methods in NetcdfFiles:
 NetcdfFile ncfile = null;
 try {
   ncfile = NetcdfFiles.open(fileName);
   // do stuff
 } finally {
   if (ncfile != null) {
     ncfile.close();
   }
 }
 
Or better yet, use try-with-resources:
 try (NetcdfFile ncfile = NetcdfFiles.open(fileName)) {
   // do stuff
 }
 

Naming

Each object has a name (aka "full name") that is unique within the entire netcdf file, and a "short name" that is unique within the parent group. These coincide for objects in the root group, and so are backwards compatible with version 3 files.
  1. Variable: group1/group2/varname
  2. Structure member Variable: group1/group2/varname.s1.s2
  3. Group Attribute: group1/group2@attName
  4. Variable Attribute: group1/group2/varName@attName

  • Field Details

  • Constructor Details

    • NetcdfFile

      @Deprecated public NetcdfFile(String filename) throws IOException
      Deprecated.
      use NetcdfFiles.open( location) or NetcdfDatasets.openFile( location)
      This is can only be used for local netcdf-3 files.
      Parameters:
      filename - location
      Throws:
      IOException - if error
    • NetcdfFile

      @Deprecated public NetcdfFile(URL url) throws IOException
      Deprecated.
      use NetcdfFiles.open( http:location) or NetcdfDatasets.openFile( http:location)
      This can only be used for netcdf-3 files served over HTTP
      Parameters:
      url - HTTP URL location
      Throws:
      IOException - if error
  • Method Details

    • setDebugFlags

      @Deprecated public static void setDebugFlags(DebugFlags debugFlag)
      Deprecated.
      do not use
    • registerIOProvider

      @Deprecated public static void registerIOProvider(String className) throws IllegalAccessException, InstantiationException, ClassNotFoundException
      Deprecated.
      use NetcdfFiles.registerIOProvider
      Register an IOServiceProvider, using its class string name.
      Parameters:
      className - Class that implements IOServiceProvider.
      Throws:
      IllegalAccessException - if class is not accessible.
      InstantiationException - if class doesnt have a no-arg constructor.
      ClassNotFoundException - if class not found.
    • registerIOProvider

      @Deprecated public static void registerIOProvider(Class iospClass) throws IllegalAccessException, InstantiationException
      Deprecated.
      use NetcdfFiles.registerIOProvider
      Register an IOServiceProvider. A new instance will be created when one of its files is opened.
      Parameters:
      iospClass - Class that implements IOServiceProvider.
      Throws:
      IllegalAccessException - if class is not accessible.
      InstantiationException - if class doesnt have a no-arg constructor.
      ClassCastException - if class doesnt implement IOServiceProvider interface.
    • registerIOProvider

      @Deprecated public static void registerIOProvider(Class iospClass, boolean last) throws IllegalAccessException, InstantiationException
      Deprecated.
      use NetcdfFiles.registerIOProvider
      Register an IOServiceProvider. A new instance will be created when one of its files is opened.
      Parameters:
      iospClass - Class that implements IOServiceProvider.
      last - true=>insert at the end of the list; otherwise front
      Throws:
      IllegalAccessException - if class is not accessible.
      InstantiationException - if class doesnt have a no-arg constructor.
      ClassCastException - if class doesnt implement IOServiceProvider interface.
    • registerIOProviderPreferred

      @Deprecated public static void registerIOProviderPreferred(Class iospClass, Class target) throws IllegalAccessException, InstantiationException
      Deprecated.
      use NetcdfFiles.registerIOProvider
      Register an IOServiceProvider. A new instance will be created when one of its files is opened. This differs from the above in that it specifically locates the target iosp and inserts the new one in front of it in order to override the target. If the iospclass is already registered, remove it and reinsert. If the target class is not present, then insert at front of the registry
      Parameters:
      iospClass - Class that implements IOServiceProvider.
      target - Class to override
      Throws:
      IllegalAccessException - if class is not accessible.
      InstantiationException - if class doesnt have a no-arg constructor.
      ClassCastException - if class doesnt implement IOServiceProvider interface.
    • iospRegistered

      @Deprecated public static boolean iospRegistered(Class iospClass)
      Deprecated.
      use NetcdfFiles.iospRegistered
      See if a specific IOServiceProvider is registered
      Parameters:
      iospClass - Class for which to search
    • iospDeRegister

      @Deprecated public static boolean iospDeRegister(Class iospClass)
      Deprecated.
      use NetcdfFiles.iospDeRegister
      See if a specific IOServiceProvider is registered and if so, remove it.
      Parameters:
      iospClass - Class for which to search and remove
      Returns:
      true if class was present
    • setProperty

      @Deprecated public static void setProperty(String name, String value)
      Deprecated.
      do not use
      Set properties. Currently recognized: "syncExtendOnly", "true" or "false" (default). if true, can only extend file on a sync.
      Parameters:
      name - name of property
      value - value of property
    • open

      @Deprecated public static NetcdfFile open(String location) throws IOException
      Deprecated.
      use NetcdfFiles.open
      Open an existing netcdf file (read only).
      Parameters:
      location - location of file.
      Returns:
      the NetcdfFile.
      Throws:
      IOException - if error
    • open

      @Deprecated public static NetcdfFile open(String location, CancelTask cancelTask) throws IOException
      Deprecated.
      use NetcdfFiles.open
      Open an existing file (read only), with option of cancelling.
      Parameters:
      location - location of the file.
      cancelTask - allow task to be cancelled; may be null.
      Returns:
      NetcdfFile object, or null if cant find IOServiceProver
      Throws:
      IOException - if error
    • open

      @Deprecated public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask) throws IOException
      Deprecated.
      use NetcdfFiles.open
      Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency.
      Parameters:
      location - location of file.
      buffer_size - RandomAccessFile buffer size, if <= 0, use default size
      cancelTask - allow task to be cancelled; may be null.
      Returns:
      NetcdfFile object, or null if cant find IOServiceProver
      Throws:
      IOException - if error
    • open

      @Deprecated public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException
      Deprecated.
      use NetcdfFiles.open
      Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency, with an optional special object for the iosp.
      Parameters:
      location - location of file. This may be a
      1. local netcdf-3 filename (with a file: prefix or no prefix)
      2. remote netcdf-3 filename (with an http: prefix)
      3. local netcdf-4 filename (with a file: prefix or no prefix)
      4. local hdf-5 filename (with a file: prefix or no prefix)
      5. local iosp filename (with a file: prefix or no prefix)
      http://thredds.ucar.edu/thredds/fileServer/grib/NCEP/GFS/Alaska_191km/files/GFS_Alaska_191km_20130416_0600.grib1 If file ends with ".Z", ".zip", ".gzip", ".gz", or ".bz2", it will uncompress/unzip and write to new file without the suffix, then use the uncompressed file. It will look for the uncompressed file before it does any of that. Generally it prefers to place the uncompressed file in the same directory as the original file. If it does not have write permission on that directory, it will use the directory defined by ucar.nc2.util.DiskCache class.
      buffer_size - RandomAccessFile buffer size, if <= 0, use default size
      cancelTask - allow task to be cancelled; may be null.
      iospMessage - special iosp tweaking (sent before open is called), may be null
      Returns:
      NetcdfFile object, or null if cant find IOServiceProver
      Throws:
      IOException - if error
    • canOpen

      @Deprecated public static boolean canOpen(String location) throws IOException
      Deprecated.
      use NetcdfFiles.canOpen
      Find out if the file can be opened, but dont actually open it. Experimental.
      Parameters:
      location - same as open
      Returns:
      true if can be opened
      Throws:
      IOException - on read error
    • open

      @Deprecated public static NetcdfFile open(String location, String iospClassName, int bufferSize, CancelTask cancelTask, Object iospMessage) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException
      Deprecated.
      use NetcdfFiles.open
      Open an existing file (read only), specifying which IOSP is to be used.
      Parameters:
      location - location of file
      iospClassName - fully qualified class name of the IOSP class to handle this file
      bufferSize - RandomAccessFile buffer size, if <= 0, use default size
      cancelTask - allow task to be cancelled; may be null.
      iospMessage - special iosp tweaking (sent before open is called), may be null
      Returns:
      NetcdfFile object, or null if cant find IOServiceProver
      Throws:
      IOException - if read error
      ClassNotFoundException - cannat find iospClassName in thye class path
      InstantiationException - if class cannot be instantiated
      IllegalAccessException - if class is not accessible
    • canonicalizeUriString

      @Deprecated public static String canonicalizeUriString(String location)
      Deprecated.
      use NetcdfFiles.canonicalizeUriString
      Removes the "file:" or "file://" prefix from the location, if necessary. Also replaces back slashes with forward slashes.
      Parameters:
      location - a URI string.
      Returns:
      a canonical URI string.
    • openInMemory

      @Deprecated public static NetcdfFile openInMemory(String name, byte[] data, String iospClassName) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException
      Deprecated.
      use NetcdfFiles.openInMemory
      Open an in-memory netcdf file, with a specific iosp.
      Parameters:
      name - name of the dataset. Typically use the filename or URI.
      data - in-memory netcdf file
      iospClassName - fully qualified class name of the IOSP class to handle this file
      Returns:
      NetcdfFile object, or null if cant find IOServiceProver
      Throws:
      IOException - if read error
      ClassNotFoundException - cannat find iospClassName in the class path
      InstantiationException - if class cannot be instantiated
      IllegalAccessException - if class is not accessible
    • openInMemory

      @Deprecated public static NetcdfFile openInMemory(String name, byte[] data) throws IOException
      Deprecated.
      use NetcdfFiles.openInMemory
      Open an in-memory netcdf file.
      Parameters:
      name - name of the dataset. Typically use the filename or URI.
      data - in-memory netcdf file
      Returns:
      memory-resident NetcdfFile
      Throws:
      IOException - if error
    • openInMemory

      @Deprecated public static NetcdfFile openInMemory(String filename) throws IOException
      Deprecated.
      use NetcdfFiles.openInMemory
      Read a local CDM file into memory. All reads are then done from memory.
      Parameters:
      filename - location of CDM file, must be a local file.
      Returns:
      a NetcdfFile, which is completely in memory
      Throws:
      IOException - if error reading file
    • openInMemory

      @Deprecated public static NetcdfFile openInMemory(URI uri) throws IOException
      Deprecated.
      use NetcdfFiles.openInMemory
      Read a remote CDM file into memory. All reads are then done from memory.
      Parameters:
      uri - location of CDM file, must be accessible through url.toURL().openStream().
      Returns:
      a NetcdfFile, which is completely in memory
      Throws:
      IOException - if error reading file
    • open

      @Deprecated public static NetcdfFile open(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage) throws IOException
      Deprecated.
      use NetcdfFiles.open
      Open a RandomAccessFile as a NetcdfFile, if possible.
      Parameters:
      raf - The open raf, is not cloised by this method.
      location - human readable locatoin of this dataset.
      cancelTask - used to monitor user cancellation; may be null.
      iospMessage - send this message to iosp; may be null.
      Returns:
      NetcdfFile or throw an Exception.
      Throws:
      IOException - if cannot open as a CDM NetCDF.
    • close

      public void close() throws IOException
      Close all resources (files, sockets, etc) associated with this file. If the underlying file was acquired, it will be released, otherwise closed. if isClosed() already, nothing will happen
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ucar.nc2.util.cache.FileCacheable
      Throws:
      IOException - if error when closing
    • release

      @Deprecated public void release() throws IOException
      Deprecated.
      do not use
      Public by accident. Release any resources like file handles
      Specified by:
      release in interface ucar.nc2.util.cache.FileCacheable
      Throws:
      IOException
    • reacquire

      @Deprecated public void reacquire() throws IOException
      Deprecated.
      do not use
      Public by accident. Reacquire any resources like file handles
      Specified by:
      reacquire in interface ucar.nc2.util.cache.FileCacheable
      Throws:
      IOException
    • setFileCache

      @Deprecated public void setFileCache(ucar.nc2.util.cache.FileCacheIF cache)
      Deprecated.
      do not use
      Public by accident. Optional file caching.
      Specified by:
      setFileCache in interface ucar.nc2.util.cache.FileCacheable
    • getCacheName

      @Deprecated public String getCacheName()
      Deprecated.
      do not use
      Public by accident. Get the name used in the cache, if any.
      Returns:
      name in the cache.
    • getLocation

      public String getLocation()
      Get the NetcdfFile location. This is a URL, or a file pathname.
      Specified by:
      getLocation in interface ucar.nc2.util.cache.FileCacheable
      Returns:
      location URL or file pathname.
    • getId

      @Nullable public String getId()
      Get the globally unique dataset identifier, if it exists.
      Returns:
      id, or null if none.
    • getTitle

      @Nullable public String getTitle()
      Get the human-readable title, if it exists.
      Returns:
      title, or null if none.
    • getRootGroup

      public Group getRootGroup()
      Get the root group.
      Returns:
      root group
    • findGroup

      @Nullable public Group findGroup(@Nullable String fullName)
      Find a Group, with the specified (full) name. A full name should start with a '/'. For backwards compatibility, we accept full names that omit the leading '/'. An embedded '/' separates subgroup names.
      Parameters:
      fullName - eg "/group/subgroup/wantGroup". Null or empty string returns the root group.
      Returns:
      Group or null if not found.
    • findVariable

      @Deprecated @Nullable public Variable findVariable(Group g, String shortName)
      Deprecated.
      use g.findVariable(shortName)
      Find a Variable by short name, in the given group.
      Parameters:
      g - A group in this file. Null for root group.
      shortName - short name of the Variable.
      Returns:
      Variable if found, else null.
    • findVariable

      @Nullable public Variable findVariable(String fullNameEscaped)
      Find a Variable, with the specified (escaped full) name. It may possibly be nested in multiple groups and/or structures. An embedded "." is interpreted as structure.member. An embedded "/" is interpreted as group/variable. If the name actually has a ".", you must escape it (call NetcdfFiles.makeValidPathName(varname)) Any other chars may also be escaped, as they are removed before testing.
      Parameters:
      fullNameEscaped - eg "/group/subgroup/name1.name2.name".
      Returns:
      Variable or null if not found.
    • findVariableByAttribute

      @Deprecated @Nullable public Variable findVariableByAttribute(Group g, String attName, String attValue)
      Deprecated.
      use g.findVariableByAttribute(String attName, String attValue)
      Look in the given Group and in its nested Groups for a Variable with a String valued Attribute with the given name and value.
      Parameters:
      g - start with this Group, null for the root Group.
      attName - look for an Attribuite with this name.
      attValue - look for an Attribuite with this value.
      Returns:
      the first Variable that matches, or null if none match.
    • findDimension

      @Nullable public Dimension findDimension(String fullName)
      Finds a Dimension with the specified full name. It may be nested in multiple groups. An embedded "/" is interpreted as a group separator. A leading slash indicates the root group. That slash may be omitted, but the fullName will be treated as if it were there. In other words, the first name token in fullName is treated as the short name of a Group or Dimension, relative to the root group.
      Parameters:
      fullName - Dimension full name, e.g. "/group/subgroup/dim".
      Returns:
      the Dimension or null if it wasn't found.
    • hasUnlimitedDimension

      public boolean hasUnlimitedDimension()
      Return true if this file has one or more unlimited (record) dimension.
      Returns:
      if this file has an unlimited Dimension(s)
    • getUnlimitedDimension

      @Nullable public Dimension getUnlimitedDimension()
      Return the unlimited (record) dimension, or null if not exist. If there are multiple unlimited dimensions, it will return the first one.
      Returns:
      the unlimited Dimension, or null if none.
    • getDimensions

      @Deprecated public com.google.common.collect.ImmutableList<Dimension> getDimensions()
      Deprecated.
      use ncfile.getRootGroup().getDimensions() for files without nested groups, or recurse through nested groups to get dimensions.
      Get the shared Dimensions used in this file.

      If the dimensions are in a group, the dimension name will have the group name, in order to disambiguate the dimensions. This means that a Variable's dimensions will not match Dimensions in this list. Therefore it is better to get the shared Dimensions directly from the Groups.

    • getVariables

      public com.google.common.collect.ImmutableList<Variable> getVariables()
      Get all of the variables in the file, in all groups. Alternatively, use groups.
    • getGlobalAttributes

      public com.google.common.collect.ImmutableList<Attribute> getGlobalAttributes()
      Returns the set of global attributes associated with this file, which are the attributes associated with the root group, or any subgroup. Alternatively, use groups.
    • findGlobalAttribute

      @Nullable public Attribute findGlobalAttribute(String attName)
      Look up an Attribute by (short) name in the root Group or nested Groups, exact match.
      Parameters:
      attName - the name of the attribute
      Returns:
      the first Group attribute with given name, or null if not found
    • findGlobalAttributeIgnoreCase

      @Nullable public Attribute findGlobalAttributeIgnoreCase(String name)
      Look up an Attribute by (short) name in the root Group or nested Groups, ignore case.
      Parameters:
      name - the name of the attribute
      Returns:
      the first group attribute with given Attribute name, ignoronmg case, or null if not found
    • findAttribute

      @Nullable public Attribute findAttribute(String fullNameEscaped)
      Find an attribute, with the specified (escaped full) name. It may possibly be nested in multiple groups and/or structures. An embedded "." is interpreted as structure.member. An embedded "/" is interpreted as group/group or group/variable. An embedded "@" is interpreted as variable@attribute If the name actually has a ".", you must escape it (call NetcdfFiles.makeValidPathName(varname)) Any other chars may also be escaped, as they are removed before testing.
      Parameters:
      fullNameEscaped - eg "@attName", "/group/subgroup/@attName" or "/group/subgroup/varname.name2.name@attName"
      Returns:
      Attribute or null if not found.
    • findAttValueIgnoreCase

      @Deprecated public String findAttValueIgnoreCase(Variable v, String attName, String defaultValue)
      Deprecated.
      use getRootGroup() or Variable attributes().findAttributeString().
      Find a String-valued global or variable Attribute by Attribute name (ignore case), return the Value of the Attribute. If not found return defaultValue
      Parameters:
      v - the variable or null to look in the root group.
      attName - the (full) name of the attribute, case insensitive
      defaultValue - return this if attribute not found
      Returns:
      the attribute value, or defaultValue if not found
    • readAttributeDouble

      @Deprecated public double readAttributeDouble(Variable v, String attName, double defValue)
      Deprecated.
      use use getRootGroup() or Variable attributes().findAttributeDouble
    • readAttributeInteger

      @Deprecated public int readAttributeInteger(Variable v, String attName, int defValue)
      Deprecated.
      use use getRootGroup() or Variable attributes().findAttributeInteger
    • toString

      public String toString()
      CDL representation of Netcdf header info, non strict
      Overrides:
      toString in class Object
    • toNcml

      public String toNcml(String url)
      NcML representation of Netcdf header info, non strict
    • writeNcml

      public void writeNcml(OutputStream os, String uri) throws IOException
      Write the NcML representation: dont show coordinate values
      Parameters:
      os - : write to this OutputStream. Will be closed at end of the method.
      uri - use this for the url attribute; if null use getLocation(). // ??
      Throws:
      IOException - if error
    • writeNcml

      public void writeNcml(Writer writer, String uri) throws IOException
      Write the NcML representation: dont show coordinate values
      Parameters:
      writer - : write to this Writer, should have encoding of UTF-8. Will be closed at end of the method.
      uri - use this for the url attribute; if null use getLocation().
      Throws:
      IOException - if error
    • writeCDL

      @Deprecated public void writeCDL(OutputStream out, boolean strict)
      Deprecated.
      use CDLWriter
      Write CDL representation to OutputStream.
      Parameters:
      out - write to this OutputStream
      strict - if true, make it stricly CDL, otherwise, add a little extra info
    • writeCDL

      @Deprecated public void writeCDL(PrintWriter pw, boolean strict)
      Deprecated.
      use CDLWriter
      Write CDL representation to PrintWriter.
      Parameters:
      pw - write to this PrintWriter
      strict - if true, make it stricly CDL, otherwise, add a little extra info
    • syncExtend

      @Deprecated public boolean syncExtend() throws IOException
      Deprecated.
      do not use
      Extend the file if needed, in a way that is compatible with the current metadata, that is, does not invalidate structural metadata held by the application. For example, ok if dimension lengths, data has changed. All previous object references (variables, dimensions, etc) remain valid.
      Returns:
      true if file was extended.
      Throws:
      IOException - if error
    • getLastModified

      @Deprecated public long getLastModified()
      Deprecated.
      Specified by:
      getLastModified in interface ucar.nc2.util.cache.FileCacheable
    • addAttribute

      @Deprecated public Attribute addAttribute(Group parent, Attribute att)
      Deprecated.
      Use NetcdfFile.builder()
      Add an attribute to a group.
      Parameters:
      parent - add to this group. If group is null, use root group
      att - add this attribute
      Returns:
      the attribute that was added
    • addAttribute

      @Deprecated public Attribute addAttribute(Group parent, String name, String value)
      Deprecated.
      Use NetcdfFile.builder()
      Add optional String attribute to a group.
      Parameters:
      parent - add to this group. If group is null, use root group
      name - attribute name, may not be null
      value - attribute value, may be null, in which case, do not addd
      Returns:
      the attribute that was added
    • addGroup

      @Deprecated public Group addGroup(Group parent, Group g)
      Deprecated.
      Use NetcdfFile.builder()
      Add a group to the parent group.
      Parameters:
      parent - add to this group. If group is null, use root group
      g - add this group
      Returns:
      the group that was added
    • setRootGroup

      @Deprecated public void setRootGroup(Group rootGroup)
      Deprecated.
      Use NetcdfFile.builder()
      Public by accident.
    • addDimension

      @Deprecated public Dimension addDimension(Group parent, Dimension d)
      Deprecated.
      Use NetcdfFile.builder()
      Add a shared Dimension to a Group.
      Parameters:
      parent - add to this group. If group is null, use root group
      d - add this Dimension
      Returns:
      the dimension that was added
    • removeDimension

      @Deprecated public boolean removeDimension(Group g, String dimName)
      Deprecated.
      Use NetcdfFile.builder()
      Remove a shared Dimension from a Group by name.
      Parameters:
      g - remove from this group. If group is null, use root group
      dimName - name of Dimension to remove.
      Returns:
      true if found and removed.
    • addVariable

      @Deprecated public Variable addVariable(Group g, Variable v)
      Deprecated.
      Use NetcdfFile.builder()
      Add a Variable to the given group.
      Parameters:
      g - add to this group. If group is null, use root group
      v - add this Variable
      Returns:
      the variable that was added
    • addVariable

      @Deprecated public Variable addVariable(Group g, String shortName, DataType dtype, String dims)
      Deprecated.
      Use NetcdfFile.builder()
      Create a new Variable, and add to the given group.
      Parameters:
      g - add to this group. If group is null, use root group
      shortName - short name of the Variable
      dtype - data type of the Variable
      dims - list of dimension names
      Returns:
      the new Variable
    • addStringVariable

      @Deprecated public Variable addStringVariable(Group g, String shortName, String dims, int strlen)
      Deprecated.
      Use NetcdfFile.builder()
      Create a new Variable of type Datatype.CHAR, and add to the given group.
      Parameters:
      g - add to this group. If group is null, use root group
      shortName - short name of the Variable
      dims - list of dimension names
      strlen - dimension length of the inner (fastest changing) dimension
      Returns:
      the new Variable
    • removeVariable

      @Deprecated public boolean removeVariable(Group g, String varName)
      Deprecated.
      Use NetcdfFile.builder()
      Remove a Variable from the given group by name.
      Parameters:
      g - remove from this group. If group is null, use root group
      varName - name of variable to remove.
      Returns:
      true is variable found and removed
    • addVariableAttribute

      @Deprecated public Attribute addVariableAttribute(Variable v, Attribute att)
      Deprecated.
      Use NetcdfFile.builder()
      Add a variable attribute.
      Parameters:
      v - add to this Variable.
      att - add this attribute
      Returns:
      the added Attribute
    • sendIospMessage

      public Object sendIospMessage(Object message)
      Generic way to send a "message" to the underlying IOSP. This message is sent after the file is open. To affect the creation of the file, use a factory method like NetcdfFile.open(). In ver6, IOSP_MESSAGE_ADD_RECORD_STRUCTURE, IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE will not work here.
      Parameters:
      message - iosp specific message
      Returns:
      iosp specific return, may be null
    • setId

      @Deprecated public void setId(String id)
      Deprecated.
      Use NetcdfFile.builder()
      Set the globally unique dataset identifier.
      Parameters:
      id - the id
    • setTitle

      @Deprecated public void setTitle(String title)
      Deprecated.
      Use NetcdfFile.builder()
      Set the dataset "human readable" title.
      Parameters:
      title - the title
    • setLocation

      @Deprecated public void setLocation(String location)
      Deprecated.
      Use NetcdfFile.builder()
      Set the location, a URL or local filename.
      Parameters:
      location - the location
    • setImmutable

      @Deprecated public NetcdfFile setImmutable()
      Deprecated.
      Use NetcdfFile.builder()
      Make this immutable.
      Returns:
      this
    • empty

      @Deprecated public void empty()
      Deprecated.
      Completely empty the objects in the netcdf file. Used for rereading the file on a sync().
    • finish

      @Deprecated public void finish()
      Deprecated.
      Use NetcdfFile.builder()
      Finish constructing the object model. This construsts the "global" variables, attributes and dimensions. It also looks for coordinate variables.
    • readSection

      public Array readSection(String variableSection) throws IOException, InvalidRangeException
      Read a variable using the given section specification. The result is always an array of the type of the innermost variable. Its shape is the accumulation of all the shapes of its parent structures.
      Parameters:
      variableSection - the constraint expression.
      Returns:
      data requested
      Throws:
      IOException - if error
      InvalidRangeException - if variableSection is invalid
      See Also:
    • readArrays

      @Deprecated public List<Array> readArrays(List<Variable> variables) throws IOException
      Deprecated.
      will be moved to DODSNetcdfFile in version 6.
      Do a bulk read on a list of Variables and return a corresponding list of Array that contains the results of a full read on each Variable. This is mostly here so DODSNetcdf can override it with one call to the server.
      Parameters:
      variables - List of type Variable
      Returns:
      List of Array, one for each Variable in the input.
      Throws:
      IOException - if read error
    • read

      @Deprecated public Array read(String variableSection, boolean flatten) throws IOException, InvalidRangeException
      Deprecated.
      use readSection(), flatten=false no longer supported
      Read a variable using the given section specification.
      Parameters:
      variableSection - the constraint expression.
      flatten - MUST BE TRUE
      Returns:
      Array data read.
      Throws:
      IOException - if error
      InvalidRangeException - if variableSection is invalid
      See Also:
    • getDetailInfo

      public String getDetailInfo()
      Show debug / underlying implementation details
    • getDetailInfo

      public void getDetailInfo(Formatter f)
    • getIosp

      @Deprecated public IOServiceProvider getIosp()
      Deprecated.
      do not use.
    • getFileTypeId

      public String getFileTypeId()
      Get the file type id for the underlying data source.
      Returns:
      registered id of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • getFileTypeDescription

      public String getFileTypeDescription()
      Get a human-readable description for this file type.
      Returns:
      description of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • getFileTypeVersion

      public String getFileTypeVersion()
      Get the version of this file type.
      Returns:
      version of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • makeValidCdmObjectName

      @Deprecated public static String makeValidCdmObjectName(String shortName)
      Deprecated.
      use NetcdfFiles.makeValidCdmObjectName
      Create a valid CDM object name. Control chars (< 0x20) are not allowed. Trailing and leading blanks are not allowed and are stripped off. A space is converted into an underscore "_". A forward slash "/" is converted into an underscore "_".
      Parameters:
      shortName - from this name
      Returns:
      valid CDM object name
    • makeValidCDLName

      @Deprecated public static String makeValidCDLName(String vname)
      Deprecated.
      use NetcdfFiles.makeValidCDLName
      Escape special characters in a netcdf short name when it is intended for use in CDL.
      Parameters:
      vname - the name
      Returns:
      escaped version of it
    • makeValidPathName

      @Deprecated public static String makeValidPathName(String vname)
      Deprecated.
      use NetcdfFiles.makeValidPathName
      Escape special characters in a netcdf short name when it is intended for use in a fullname
      Parameters:
      vname - the name
      Returns:
      escaped version of it
    • makeValidSectionSpecName

      @Deprecated public static String makeValidSectionSpecName(String vname)
      Deprecated.
      use NetcdfFiles.makeValidSectionSpecName
      Escape special characters in a netcdf short name when it is intended for use in a sectionSpec
      Parameters:
      vname - the name
      Returns:
      escaped version of it
    • makeNameUnescaped

      @Deprecated public static String makeNameUnescaped(String vname)
      Deprecated.
      use NetcdfFiles.makeNameUnescaped
      Unescape any escaped characters in a name.
      Parameters:
      vname - the escaped name
      Returns:
      unescaped version of it
    • toBuilder

      public NetcdfFile.Builder<?> toBuilder()
      Turn into a mutable Builder. Can use toBuilder().build() to copy.
    • builder

      public static NetcdfFile.Builder<?> builder()
      Get Builder for this class. Allows subclassing.
      See Also:
      • "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"