ucar.nc2
Class NCdumpW

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

public class NCdumpW
extends Object

Print contents of an existing netCDF file, using a Writer.

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)

Since:
Nov 4, 2007
Author:
caron

Nested Class Summary
static class NCdumpW.WantValues
           
 
Constructor Summary
NCdumpW()
           
 
Method Summary
static String encodeString(String s)
          Replace special characters '\t', '\n', '\f', '\r'.
static void main(String[] args)
          Main program.
static boolean print(NetcdfFile nc, String command, Writer out, CancelTask ct)
          ncdump, parsing command string, file already open.
static boolean print(NetcdfFile nc, Writer out, boolean showAll, boolean showCoords, boolean ncml, boolean strict, String varNames, CancelTask ct)
          ncdump-like print of netcdf file.
static boolean print(NetcdfFile nc, Writer out, NCdumpW.WantValues showValues, boolean ncml, boolean strict, String varNames, CancelTask ct)
          ncdump-like print of netcdf file.
static boolean print(String command, Writer out)
          NCdump that parses a command string, using default options.
static boolean print(String filename, Writer out, boolean showAll, boolean showCoords, boolean ncml, boolean strict, String varNames, CancelTask ct)
          ncdump-like print of netcdf file.
static boolean print(String command, Writer out, CancelTask ct)
          ncdump that parses a command string.
static void printArray(Array ma)
           
static void printArray(Array ma, PrintWriter out)
          Print array as undifferentiated sequence of values.
static String printArray(Array array, String name, CancelTask ct)
           
static void printArray(Array array, String name, PrintWriter out, CancelTask ct)
          Print the data array.
static boolean printHeader(String fileName, Writer out)
          Print netcdf "header only" in CDL.
static boolean printNcML(String fileName, Writer out)
          print NcML representation of this netcdf file, showing coordinate variable data.
static void printStructureData(PrintWriter out, StructureData sdata)
          Print contents of a StructureData.
static String printVariableData(VariableIF v, CancelTask ct)
          Print all the data of the given Variable.
static String printVariableDataSection(Variable v, String sectionSpec, CancelTask ct)
          Print a section of the data of the given Variable.
static String toString(Array ma)
           
static void writeNcML(NetcdfFile ncfile, Formatter out, NCdumpW.WantValues showValues, String uri)
           
static void writeNcML(NetcdfFile ncfile, Writer os, boolean showCoords, String uri)
          Write the NcML representation for a file.
static void writeNcML(NetcdfFile ncfile, Writer os, NCdumpW.WantValues showValues, String uri)
           
static void writeNcMLVariable(Variable v, Formatter out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NCdumpW

public NCdumpW()
Method Detail

printHeader

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

Parameters:
fileName - open this file
out - print to this Writer
Returns:
true if successful
Throws:
IOException - on write error

printNcML

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

Parameters:
fileName - open this file
out - print to this Writer
Returns:
true if successful
Throws:
IOException - on write error

print

public static boolean print(String command,
                            Writer out)
                     throws 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:
IOException - on write error

print

public static boolean print(String command,
                            Writer out,
                            CancelTask ct)
                     throws 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:
IOException - on write error

print

public static boolean print(NetcdfFile nc,
                            String command,
                            Writer out,
                            CancelTask ct)
                     throws 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:
IOException - on write error

print

public static boolean print(String filename,
                            Writer out,
                            boolean showAll,
                            boolean showCoords,
                            boolean ncml,
                            boolean strict,
                            String varNames,
                            CancelTask ct)
                     throws 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:
IOException - on write error

print

public static boolean print(NetcdfFile nc,
                            Writer out,
                            boolean showAll,
                            boolean showCoords,
                            boolean ncml,
                            boolean strict,
                            String varNames,
                            CancelTask ct)
                     throws 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:
IOException - on write error

print

public static boolean print(NetcdfFile nc,
                            Writer out,
                            NCdumpW.WantValues showValues,
                            boolean ncml,
                            boolean strict,
                            String varNames,
                            CancelTask ct)
                     throws IOException
ncdump-like print of netcdf file.

Parameters:
nc - already opened NetcdfFile
out - print to this stream
showValues - do you want the variable values printed?
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:
IOException - on write error

printVariableData

public static String printVariableData(VariableIF v,
                                       CancelTask ct)
                                throws 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:
IOException - on write error

printVariableDataSection

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

Parameters:
v - variable to print
sectionSpec - string specification
ct - allow task to be cancelled; may be null.
Returns:
String result formatted data ouptut
Throws:
IOException - on write error
InvalidRangeException - is specified section doesnt match variable shape

printArray

public static void printArray(Array array,
                              String name,
                              PrintWriter out,
                              CancelTask ct)
                       throws IOException
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.
Throws:
IOException - on read error

printArray

public static String printArray(Array array,
                                String name,
                                CancelTask ct)
                         throws IOException
Throws:
IOException

printStructureData

public static void printStructureData(PrintWriter out,
                                      StructureData sdata)
                               throws IOException
Print contents of a StructureData.

Parameters:
out - send output here.
sdata - StructureData to print.
Throws:
IOException - on read error

printArray

public static void printArray(Array ma,
                              PrintWriter out)
Print array as undifferentiated sequence of values.

Parameters:
ma - any Array except ArrayStructure
out - print to here

printArray

public static void printArray(Array ma)

toString

public static String toString(Array ma)
                       throws IOException
Throws:
IOException

writeNcML

public static void writeNcML(NetcdfFile ncfile,
                             Writer os,
                             boolean showCoords,
                             String uri)
                      throws IOException
Write the NcML representation for a file. 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:
ncfile - write NcML for this file
os - write to this Writer. Must be using UTF-8 encoding (where applicable)
showCoords - show coordinate variable values.
uri - use this for the uri attribute; if null use getLocation(). // ??
Throws:
IOException - on write error

writeNcML

public static void writeNcML(NetcdfFile ncfile,
                             Writer os,
                             NCdumpW.WantValues showValues,
                             String uri)
                      throws IOException
Throws:
IOException

writeNcML

public static void writeNcML(NetcdfFile ncfile,
                             Formatter out,
                             NCdumpW.WantValues showValues,
                             String uri)
                      throws IOException
Throws:
IOException

writeNcMLVariable

public static void writeNcMLVariable(Variable v,
                                     Formatter out)
                              throws IOException
Throws:
IOException

encodeString

public static String encodeString(String s)
Replace special characters '\t', '\n', '\f', '\r'.

Parameters:
s - string to quote
Returns:
equivilent string replacing special chars

main

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

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

where:

Default is to dump the header info only.

Parameters:
args - arguments


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.