ucar.nc2.iosp.gempak
Class GempakFileReader

java.lang.Object
  extended by ucar.nc2.iosp.gempak.GempakFileReader
All Implemented Interfaces:
GempakConstants
Direct Known Subclasses:
GempakGridReader, GempakSurfaceFileReader

public class GempakFileReader
extends java.lang.Object
implements GempakConstants

Read a Gempak grid file

Version:
$Revision: 1.3 $
Author:
IDV Development Team

Nested Class Summary
protected  class GempakFileReader.DMFileHeaderInfo
          Class to hold the DM File header info
protected  class GempakFileReader.DMHeaders
          Class to mimic the DMHDRS common block.
protected  class GempakFileReader.DMKeys
          Class to mimic the DMKEYS common block.
protected  class GempakFileReader.DMLabel
          Class to mimic the GEMPAK DMLABL common block
protected  class GempakFileReader.DMParam
          Class to hold DM Parameter info
protected  class GempakFileReader.DMPart
          Class to mimic the DMKEYS common block.
protected  class GempakFileReader.Key
          Class to hold information about a key.
 
Field Summary
protected  GempakFileReader.DMLabel dmLabel
          The label common param
protected  java.util.List<GempakFileReader.DMFileHeaderInfo> fileHeaderInfo
          header info
protected  long fileSize
          file size
protected  GempakFileReader.DMHeaders headers
          headers
protected  GempakFileReader.DMKeys keys
          key
protected  int MTMACH
          the machine type byte order
protected  boolean mvmst
          swap flag
protected  boolean needToSwap
          swap flag
protected  java.util.List<GempakFileReader.DMPart> parts
          part
protected  RandomAccessFile rf
          The file
 
Fields inherited from interface ucar.nc2.iosp.gempak.GempakConstants
COL, IMISSD, LLGDHD, LLNANL, LLNNAV, LLSTHL, MBLKSZ, MDCHAR, MDGDEC, MDGDIF, MDGGRB, MDGNMC, MDGNON, MDGRB2, MDGRID, MDINTG, MDREAL, MDRPCK, MFGD, MFSF, MFSN, MTALPH, MTAPOL, MTHP, MTIBM, MTIGPH, MTIRIS, MTLNUX, MTSUN, MTULTX, MTVAX, RDIFFD, RMISSD, ROW
 
Constructor Summary
GempakFileReader()
          Bean ctor
GempakFileReader(RandomAccessFile raf)
          Create a Gempak File Reader from the file
GempakFileReader(java.lang.String filename)
          Create a Gempak File Reader from the file
 
Method Summary
 float DM_RFLT(int word)
          Read a float
 void DM_RFLT(int word, float[] rarray)
          Convenience method to fully read into an array of floats
 void DM_RFLT(int word, int num, float[] rarray, int start)
          Read into an array of ints.
 int DM_RINT(int word)
          Read an integer
 void DM_RINT(int word, int[] iarray)
          Convenience method to fully read into an array of ints
 void DM_RINT(int word, int num, int[] iarray, int start)
          Read into an array of ints.
 java.lang.String DM_RSTR(int isword)
          Read a 4-byte String
 java.lang.String DM_RSTR(int isword, int nchar)
          Read a String
 GempakFileReader.DMFileHeaderInfo findFileHeader(java.lang.String name)
          Find the file header with this name
 GempakFileReader.Key findKey(java.lang.String name)
          Find a key with the given name
 int getByteOrder()
          Get the byte order for this system
 int getByteOrder(int kmachn)
          Get the byte order for the machine type.
 int getDataPointer(int irow, int icol, java.lang.String partName)
          Get the pointer to the data.
 float[] getFileHeader(java.lang.String name)
          Read in the values for the file header
 java.lang.String getFilename()
          Get the file name.
 long getInitFileSize()
          Get initial file size
static long getOffset(int fortranWord)
          Get the byte offset in 0 based space from a 1 based 4 byte FORTRAN word.
 GempakFileReader.DMPart getPart(java.lang.String name)
          Find the part with the particular name.
 int getPartNumber(java.lang.String name)
          Find the part with the particular name.
protected  boolean init(boolean fullCheck)
          Initialize the file, read in all the metadata (ala DM_OPEN)
 void init(RandomAccessFile raf, boolean fullCheck)
          Initialize the file, read in all the metadata (ala DM_OPEN)
protected  void logError(java.lang.String errMsg)
          Log an error
static void main(java.lang.String[] args)
          Run the program
 void printFileLabel()
          Print the file label
 void printHeaders()
          Print the row and column keys
 void printKeys()
          Print the row and column keys
 void printParts()
          Print the part information
protected  void readFileHeaderInfo()
          Read the file header info (DM_RFIL)
protected  void readHeaders()
          Read the headers (DM_RHDA)
protected  void readKeys()
          Read in the row and column keys (DM_KEY)
protected  void readParts()
          Read the parts (DM_RPRT)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rf

protected RandomAccessFile rf
The file


dmLabel

protected GempakFileReader.DMLabel dmLabel
The label common param


fileHeaderInfo

protected java.util.List<GempakFileReader.DMFileHeaderInfo> fileHeaderInfo
header info


headers

protected GempakFileReader.DMHeaders headers
headers


keys

protected GempakFileReader.DMKeys keys
key


parts

protected java.util.List<GempakFileReader.DMPart> parts
part


MTMACH

protected int MTMACH
the machine type byte order


mvmst

protected boolean mvmst
swap flag


needToSwap

protected boolean needToSwap
swap flag


fileSize

protected long fileSize
file size

Constructor Detail

GempakFileReader

public GempakFileReader()
Bean ctor


GempakFileReader

public GempakFileReader(java.lang.String filename)
                 throws java.io.IOException
Create a Gempak File Reader from the file

Parameters:
filename - filename
Throws:
java.io.IOException - problem reading file

GempakFileReader

public GempakFileReader(RandomAccessFile raf)
                 throws java.io.IOException
Create a Gempak File Reader from the file

Parameters:
raf - file to read from
Throws:
java.io.IOException - problem reading file
Method Detail

init

public final void init(RandomAccessFile raf,
                       boolean fullCheck)
                throws java.io.IOException
Initialize the file, read in all the metadata (ala DM_OPEN)

Parameters:
raf - RandomAccessFile to read.
fullCheck - if true, check entire structure
Throws:
java.io.IOException - problem reading file

init

protected boolean init(boolean fullCheck)
                throws java.io.IOException
Initialize the file, read in all the metadata (ala DM_OPEN)

Parameters:
fullCheck - if true, check entire structure
Returns:
true if successful
Throws:
java.io.IOException - problem reading file

getFilename

public java.lang.String getFilename()
Get the file name.

Returns:
the name of the file

getInitFileSize

public long getInitFileSize()
Get initial file size

Returns:
the file size when init was called.

getByteOrder

public int getByteOrder()
Get the byte order for this system

Returns:
byte order

getByteOrder

public int getByteOrder(int kmachn)
Get the byte order for the machine type.

Parameters:
kmachn - maching type
Returns:
byte order

readFileHeaderInfo

protected void readFileHeaderInfo()
                           throws java.io.IOException
Read the file header info (DM_RFIL)

Throws:
java.io.IOException - problem reading file

readKeys

protected void readKeys()
                 throws java.io.IOException
Read in the row and column keys (DM_KEY)

Throws:
java.io.IOException - problem reading file

readHeaders

protected void readHeaders()
                    throws java.io.IOException
Read the headers (DM_RHDA)

Throws:
java.io.IOException - problem reading file

readParts

protected void readParts()
                  throws java.io.IOException
Read the parts (DM_RPRT)

Throws:
java.io.IOException - problem reading file

getOffset

public static long getOffset(int fortranWord)
Get the byte offset in 0 based space from a 1 based 4 byte FORTRAN word.

Parameters:
fortranWord - 1 based word offset
Returns:
byte offset to that word

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Run the program

Parameters:
args - filename
Throws:
java.io.IOException - problem reading the file

findKey

public GempakFileReader.Key findKey(java.lang.String name)
Find a key with the given name

Parameters:
name - the name of the key
Returns:
the key or null;

findFileHeader

public GempakFileReader.DMFileHeaderInfo findFileHeader(java.lang.String name)
Find the file header with this name

Parameters:
name - name of header
Returns:
headerinfo or null if not found

getFileHeader

public float[] getFileHeader(java.lang.String name)
                      throws java.io.IOException
Read in the values for the file header

Parameters:
name - name of header
Returns:
values or null if not found
Throws:
java.io.IOException - problem reading file

logError

protected void logError(java.lang.String errMsg)
Log an error

Parameters:
errMsg - message to log

printFileLabel

public void printFileLabel()
Print the file label


printKeys

public void printKeys()
Print the row and column keys


printHeaders

public void printHeaders()
Print the row and column keys


printParts

public void printParts()
Print the part information


getPartNumber

public int getPartNumber(java.lang.String name)
Find the part with the particular name.

Parameters:
name - name of part to find
Returns:
part number.

getPart

public GempakFileReader.DMPart getPart(java.lang.String name)
Find the part with the particular name.

Parameters:
name - name of part to find
Returns:
part or null if not found

getDataPointer

public int getDataPointer(int irow,
                          int icol,
                          java.lang.String partName)
Get the pointer to the data. Taken from DM_RDTR

Parameters:
irow - row number
icol - column number
partName - name of the part
Returns:
word (1 based) of start of data.

DM_RINT

public int DM_RINT(int word)
            throws java.io.IOException
Read an integer

Parameters:
word - word in file (1 based) to read
Returns:
int read
Throws:
java.io.IOException - problem reading file

DM_RINT

public void DM_RINT(int word,
                    int[] iarray)
             throws java.io.IOException
Convenience method to fully read into an array of ints

Parameters:
word - word in file (1 based) to read
iarray - array to read into
Throws:
java.io.IOException - problem reading file

DM_RINT

public void DM_RINT(int word,
                    int num,
                    int[] iarray,
                    int start)
             throws java.io.IOException
Read into an array of ints.

Parameters:
word - word in file (1 based) to read
iarray - array to read into
start - starting word in the array (0 based)
num - number of words to read
Throws:
java.io.IOException - problem reading file

DM_RFLT

public float DM_RFLT(int word)
              throws java.io.IOException
Read a float

Parameters:
word - word in file (1 based) to read
Returns:
float read
Throws:
java.io.IOException - problem reading file

DM_RFLT

public void DM_RFLT(int word,
                    float[] rarray)
             throws java.io.IOException
Convenience method to fully read into an array of floats

Parameters:
word - word in file (1 based) to read
rarray - array to read into
Throws:
java.io.IOException - problem reading file

DM_RFLT

public void DM_RFLT(int word,
                    int num,
                    float[] rarray,
                    int start)
             throws java.io.IOException
Read into an array of ints.

Parameters:
word - word in file (1 based) to read
num - number of words to read
rarray - array to read into
start - starting word in the array (0 based)
Throws:
java.io.IOException - problem reading file

DM_RSTR

public java.lang.String DM_RSTR(int isword)
                         throws java.io.IOException
Read a 4-byte String

Parameters:
isword - offset in file (1 based FORTRAN word)
Returns:
String read
Throws:
java.io.IOException - problem reading file

DM_RSTR

public java.lang.String DM_RSTR(int isword,
                                int nchar)
                         throws java.io.IOException
Read a String

Parameters:
isword - offset in file (1 based FORTRAN word)
nchar - number of characters to read
Returns:
String read
Throws:
java.io.IOException - problem reading file