ucar.nc2
Class NCdump

java.lang.Object
  extended by ucar.nc2.NCdump

public class NCdump
extends java.lang.Object

Print contents of an existing netCDF file of unknown structure, like ncdump. A difference with ncdump is that the nesting of multidimensional array data is represented by nested brackets, so the output is not legal CDL that can be used as input for ncgen. Also, the default is header only (-h)

Version:
$Id:NCdump.java 51 2006-07-12 17:13:13Z caron $
Author:
Russ Rew, John Caron

Nested Class Summary
static class NCdump.CEresult
          public by accident
 
Constructor Summary
NCdump()
           
 
Method Summary
static void main(java.lang.String[] args)
          Main program.
static java.lang.String makeSectionString(VariableIF v, java.util.List ranges)
          Make section specification String from a range list for a Variable.
static NCdump.CEresult parseVariableSection(NetcdfFile ncfile, java.lang.String variableSection)
          Parse a section specification String.
static boolean print(NetcdfFile nc, java.io.OutputStream out, boolean showAll, boolean showCoords, boolean ncml, boolean strict, java.lang.String varNames, CancelTask ct)
          ncdump-like print of netcdf file.
static boolean print(NetcdfFile nc, java.lang.String command, java.io.OutputStream out, CancelTask ct)
          ncdump, parsing command string, file already open.
static boolean print(java.lang.String command, java.io.OutputStream out)
          NCdump that parses a command string, using default options.
static boolean print(java.lang.String fileName, java.io.OutputStream out, boolean showAll, boolean showCoords, boolean ncml, boolean strict, java.lang.String varNames, CancelTask ct)
          ncdump-like print of netcdf file.
static boolean print(java.lang.String command, java.io.OutputStream out, CancelTask ct)
          ncdump that parses a command string.
static void printArray(Array array, java.lang.String name, java.io.PrintStream out, CancelTask ct)
          Print the data array.
static boolean printHeader(java.lang.String fileName, java.io.OutputStream out)
          Print netcdf "header only" in CDL.
static boolean printNcML(java.lang.String fileName, java.io.OutputStream out)
          print NcML representation of this netcdf file, showing coordinate variable data.
static void printStructureData(java.io.PrintStream out, StructureData sdata)
          Print contents of a StructureData.
static java.lang.String printVariableData(VariableIF v, CancelTask ct)
          Print all the data of the given Variable.
static java.lang.String printVariableDataSection(VariableIF v, java.lang.String sectionSpec, CancelTask ct)
          Print a section the data of the given Variable.
static void writeNcML(NetcdfFile ncfile, java.io.OutputStream os, boolean showCoords, java.lang.String uri)
          Write the NcML representation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NCdump

public NCdump()
Method Detail

printHeader

public static boolean printHeader(java.lang.String fileName,
                                  java.io.OutputStream out)
                           throws java.io.IOException
Print netcdf "header only" in CDL.

Parameters:
fileName - open this file
out - print to this stream
Returns:
true if successful
Throws:
java.io.IOException

printNcML

public static boolean printNcML(java.lang.String fileName,
                                java.io.OutputStream out)
                         throws java.io.IOException
print NcML representation of this netcdf file, showing coordinate variable data.

Parameters:
fileName - open this file
out - print to this stream
Returns:
true if successful
Throws:
java.io.IOException

print

public static boolean print(java.lang.String command,
                            java.io.OutputStream out)
                     throws java.io.IOException
NCdump that parses a command string, using default options. Usage:
NCdump filename [-ncml] [-c | -vall] [-v varName;...]

Parameters:
command - command string
out - send output here
Returns:
true if successful
Throws:
java.io.IOException

print

public static boolean print(java.lang.String command,
                            java.io.OutputStream out,
                            CancelTask ct)
                     throws java.io.IOException
ncdump that parses a command string. Usage:
NCdump filename [-ncml] [-c | -vall] [-v varName;...]

Parameters:
command - command string
out - send output here
ct - allow task to be cancelled; may be null.
Returns:
true if successful
Throws:
java.io.IOException

print

public static boolean print(NetcdfFile nc,
                            java.lang.String command,
                            java.io.OutputStream out,
                            CancelTask ct)
                     throws java.io.IOException
ncdump, parsing command string, file already open.

Parameters:
nc - apply command to this file
command - : command string
out - send output here
ct - allow task to be cancelled; may be null.
Returns:
true if successful
Throws:
java.io.IOException

print

public static boolean print(java.lang.String fileName,
                            java.io.OutputStream out,
                            boolean showAll,
                            boolean showCoords,
                            boolean ncml,
                            boolean strict,
                            java.lang.String varNames,
                            CancelTask ct)
                     throws java.io.IOException
ncdump-like print of netcdf file.

Parameters:
fileName - NetcdfFile to open
out - print to this stream
showAll - dump all variable data
showCoords - only print header and coordinate variables
ncml - print NcML representation (other arguments are ignored)
strict - print strict CDL representation
varNames - semicolon delimited list of variables whose data should be printed
ct - allow task to be cancelled; may be null.
Returns:
true if successful
Throws:
java.io.IOException

print

public static boolean print(NetcdfFile nc,
                            java.io.OutputStream out,
                            boolean showAll,
                            boolean showCoords,
                            boolean ncml,
                            boolean strict,
                            java.lang.String varNames,
                            CancelTask ct)
                     throws java.io.IOException
ncdump-like print of netcdf file.

Parameters:
nc - already opened NetcdfFile
out - print to this stream
showAll - dump all variable data
showCoords - only print header and coordinate variables
ncml - print NcML representation (other arguments are ignored)
strict - print strict CDL representation
varNames - semicolon delimited list of variables whose data should be printed. May have Fortran90 like selector: eg varName(1:2,*,2)
ct - allow task to be cancelled; may be null.
Returns:
true if successful
Throws:
java.io.IOException

parseVariableSection

public static NCdump.CEresult parseVariableSection(NetcdfFile ncfile,
                                                   java.lang.String variableSection)
                                            throws InvalidRangeException
Parse a section specification String. These have the form:
  section specification := selector | selector '.' selector
  selector := varName ['(' dims ')']
  varName := STRING

   dims := dim | dim, dims
   dim := ':' | slice | start ':' end | start ':' end ':' stride
   slice := INTEGER
   start := INTEGER
   stride := INTEGER
   end := INTEGER
 
Nonterminals are in lower case, terminals are in upper case, literals are in single quotes. Optional components are enclosed between square braces '[' and ']'.

Parameters:
ncfile - look for variable in here
variableSection - the string to parse, eg "record(12).wind(1:20,:,3)"
Returns:
return CEresult which has the equivilent Variable
Throws:
java.lang.IllegalArgumentException - when token is misformed, or variable name doesnt exist in ncfile
InvalidRangeException
See Also:
Range.parseSpec(String sectionSpec)

makeSectionString

public static java.lang.String makeSectionString(VariableIF v,
                                                 java.util.List ranges)
                                          throws InvalidRangeException
Make section specification String from a range list for a Variable.

Parameters:
v - for this Variable.
ranges - list of Range. Must includes all parent structures. The list be null, meaning use all. Individual ranges may be null, meaning all for that dimension.
Returns:
section specification String.
Throws:
InvalidRangeException

printVariableData

public static java.lang.String printVariableData(VariableIF v,
                                                 CancelTask ct)
                                          throws java.io.IOException
Print all the data of the given Variable.

Parameters:
v - variable to print
ct - allow task to be cancelled; may be null.
Returns:
String result
Throws:
java.io.IOException

printVariableDataSection

public static java.lang.String printVariableDataSection(VariableIF v,
                                                        java.lang.String sectionSpec,
                                                        CancelTask ct)
                                                 throws java.io.IOException,
                                                        InvalidRangeException
Print a section the data of the given Variable.

Parameters:
v - variable to print
ct - allow task to be cancelled; may be null.
Returns:
String result
Throws:
java.io.IOException
InvalidRangeException

printArray

public static void printArray(Array array,
                              java.lang.String name,
                              java.io.PrintStream out,
                              CancelTask ct)
Print the data array.

Parameters:
array - data to print.
name - title the output.
out - send output here.
ct - allow task to be cancelled; may be null.

printStructureData

public static void printStructureData(java.io.PrintStream out,
                                      StructureData sdata)
Print contents of a StructureData.

Parameters:
out - send output here.
sdata - StructureData to print.

writeNcML

public static void writeNcML(NetcdfFile ncfile,
                             java.io.OutputStream os,
                             boolean showCoords,
                             java.lang.String uri)
                      throws java.io.IOException
Write the NcML representation. Note that ucar.nc2.dataset.NcMLWriter has a JDOM implementation, for complete NcML. This method implements only the "core" NcML for plain ole netcdf files.

Parameters:
os - write to this Output Stream.
showCoords - show coordinate variable values.
uri - use this for the uri attribute; if null use getLocation(). // ??
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Main program.

ucar.nc2.NCdump filename [-cdl | -ncml] [-c | -vall] [-v varName1;varName2;..] [-v varName(0:1,:,12)]

where:

Deafult is to dump the header info only.