Package ucar.nc2.iosp.gempak
Class GempakFileReader
- java.lang.Object
-
- ucar.nc2.iosp.gempak.GempakFileReader
-
- All Implemented Interfaces:
GempakConstants
- Direct Known Subclasses:
AbstractGempakStationFileReader
,GempakGridReader
public class GempakFileReader extends Object implements GempakConstants
Read a Gempak grid file
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
GempakFileReader.DMFileHeaderInfo
Class to hold the DM File header infoprotected static class
GempakFileReader.DMHeaders
Class to mimic the DMHDRS common block.protected class
GempakFileReader.DMKeys
Class to mimic the DMKEYS common block.protected static class
GempakFileReader.DMParam
Class to hold DM Parameter infoprotected static class
GempakFileReader.DMPart
Class to mimic the DMKEYS common block.protected static class
GempakFileReader.Key
Class to hold information about a key.protected static class
GempakFileReader.PackingInfo
Class to hold DM Integer packing infostatic class
GempakFileReader.RData
A class to hold real (float) data
-
Field Summary
Fields Modifier and Type Field Description protected ucar.nc2.iosp.gempak.GempakFileReader.DMLabel
dmLabel
The label common paramprotected List<GempakFileReader.DMFileHeaderInfo>
fileHeaderInfo
header infoprotected long
fileSize
file sizeprotected GempakFileReader.DMHeaders
headers
headersprotected GempakFileReader.DMKeys
keys
keyprotected int
MTMACH
the machine type byte orderprotected boolean
mvmst
swap flagprotected boolean
needToSwap
swap flagprotected List<GempakFileReader.DMPart>
parts
partprotected 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GempakFileReader.RData
DM_RDTR(int irow, int icol, String partName)
Read the dataGempakFileReader.RData
DM_RDTR(int irow, int icol, String partName, int decimalScale)
Read the real (float) datafloat
DM_RFLT(int word)
Read a floatvoid
DM_RFLT(int word, float[] rarray)
Convenience method to fully read into an array of floatsvoid
DM_RFLT(int word, int num, float[] rarray, int start)
Read into an array of ints.int
DM_RINT(int word)
Read an integervoid
DM_RINT(int word, int[] iarray)
Convenience method to fully read into an array of intsvoid
DM_RINT(int word, int num, int[] iarray, int start)
Read into an array of ints.float[]
DM_RPKG(int isword, int nword, int decimalScale)
subclass should implementString
DM_RSTR(int isword)
Read a 4-byte StringString
DM_RSTR(int isword, int nchar)
Read a Stringfloat[]
DM_UNPK(GempakFileReader.DMPart part, int[] ibitst)
Unpack an array of packed integers.GempakFileReader.DMFileHeaderInfo
findFileHeader(String name)
Find the file header with this nameGempakFileReader.Key
findKey(String name)
Find a key with the given nameprotected static String
getBits(int b)
Get a bit string for an integerint
getByteOrder()
Get the byte order for this systemint
getByteOrder(int kmachn)
Get the byte order for the machine type.int
getDataPointer(int irow, int icol, String partName)
Get the pointer to the data.String
getErrorMessage()
static RandomAccessFile
getFile(String filename)
Get a RandomAccessFile for the file locationfloat[]
getFileHeader(String name)
Read in the values for the file headerString
getFilename()
Get the file name.long
getInitFileSize()
Get initial file sizestatic GempakFileReader
getInstance(RandomAccessFile raf, boolean fullCheck)
Initialize the file, read in all the metadata (ala DM_OPEN)static long
getOffset(int fortranWord)
Get the byte offset in 0 based space from a 1 based 4 byte FORTRAN word.GempakFileReader.DMPart
getPart(String name)
Find the part with the particular name.int
getPartNumber(String name)
Find the part with the particular name.protected boolean
init()
Initialize this reader.protected boolean
init(boolean fullCheck)
Initialize the file, read in all the metadata (ala DM_OPEN)boolean
init(RandomAccessFile raf, boolean fullCheck)
Initialize the file, read in all the metadata (ala DM_OPEN)protected void
logError(String errMsg)
Log an errorvoid
printFileLabel()
Print the file labelvoid
printHeaders()
Print the row and column keysvoid
printKeys()
Print the row and column keysvoid
printParts()
Print the part informationprotected 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)
-
-
-
Field Detail
-
rf
protected RandomAccessFile rf
The file
-
dmLabel
protected ucar.nc2.iosp.gempak.GempakFileReader.DMLabel dmLabel
The label common param
-
fileHeaderInfo
protected List<GempakFileReader.DMFileHeaderInfo> fileHeaderInfo
header info
-
headers
protected GempakFileReader.DMHeaders headers
headers
-
keys
protected GempakFileReader.DMKeys keys
key
-
parts
protected 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
-
-
Method Detail
-
getFile
public static RandomAccessFile getFile(String filename) throws IOException
Get a RandomAccessFile for the file location- Parameters:
filename
- filename to read.- Returns:
- RandomAccessFile
- Throws:
IOException
- problem reading file
-
getInstance
public static GempakFileReader getInstance(RandomAccessFile raf, boolean fullCheck) throws IOException
Initialize the file, read in all the metadata (ala DM_OPEN)- Parameters:
raf
- RandomAccessFile to read.fullCheck
- if true, check entire structure- Returns:
- a GempakFileReader
- Throws:
IOException
- problem reading file
-
init
public boolean init(RandomAccessFile raf, boolean fullCheck) throws IOException
Initialize the file, read in all the metadata (ala DM_OPEN)- Parameters:
raf
- RandomAccessFile to read.fullCheck
- if true, check entire structure- Throws:
IOException
- problem reading file
-
init
protected boolean init() throws IOException
Initialize this reader. Read all the metadata- Returns:
- true if successful
- Throws:
IOException
- problem reading the data
-
init
protected boolean init(boolean fullCheck) throws IOException
Initialize the file, read in all the metadata (ala DM_OPEN)- Parameters:
fullCheck
- if true, check entire structure- Returns:
- true if successful
- Throws:
IOException
- problem reading file
-
getFilename
public String getFilename()
Get the file name.- Returns:
- the name of the file
-
getErrorMessage
public String getErrorMessage()
-
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 IOException
Read the file header info (DM_RFIL)- Throws:
IOException
- problem reading file
-
readKeys
protected void readKeys() throws IOException
Read in the row and column keys (DM_KEY)- Throws:
IOException
- problem reading file
-
readHeaders
protected void readHeaders() throws IOException
Read the headers (DM_RHDA)- Throws:
IOException
- problem reading file
-
readParts
protected void readParts() throws IOException
Read the parts (DM_RPRT)- Throws:
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
-
findKey
public GempakFileReader.Key findKey(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(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(String name) throws IOException
Read in the values for the file header- Parameters:
name
- name of header- Returns:
- values or null if not found
- Throws:
IOException
- problem reading file
-
logError
protected void logError(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(String name)
Find the part with the particular name.- Parameters:
name
- name of part to find- Returns:
- part number.
-
getPart
public GempakFileReader.DMPart getPart(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, String partName)
Get the pointer to the data. Taken from DM_RDTR- Parameters:
irow
- row numbericol
- column numberpartName
- name of the part- Returns:
- word (1 based) of start of data.
-
DM_RINT
public int DM_RINT(int word) throws IOException
Read an integer- Parameters:
word
- word in file (1 based) to read- Returns:
- int read
- Throws:
IOException
- problem reading file
-
DM_RINT
public void DM_RINT(int word, int[] iarray) throws IOException
Convenience method to fully read into an array of ints- Parameters:
word
- word in file (1 based) to readiarray
- array to read into- Throws:
IOException
- problem reading file
-
DM_RINT
public void DM_RINT(int word, int num, int[] iarray, int start) throws IOException
Read into an array of ints.- Parameters:
word
- word in file (1 based) to readiarray
- array to read intostart
- starting word in the array (0 based)num
- number of words to read- Throws:
IOException
- problem reading file
-
DM_RFLT
public float DM_RFLT(int word) throws IOException
Read a float- Parameters:
word
- word in file (1 based) to read- Returns:
- float read
- Throws:
IOException
- problem reading file
-
DM_RFLT
public void DM_RFLT(int word, float[] rarray) throws IOException
Convenience method to fully read into an array of floats- Parameters:
word
- word in file (1 based) to readrarray
- array to read into- Throws:
IOException
- problem reading file
-
DM_RFLT
public void DM_RFLT(int word, int num, float[] rarray, int start) throws IOException
Read into an array of ints.- Parameters:
word
- word in file (1 based) to readnum
- number of words to readrarray
- array to read intostart
- starting word in the array (0 based)- Throws:
IOException
- problem reading file
-
DM_RSTR
public String DM_RSTR(int isword) throws IOException
Read a 4-byte String- Parameters:
isword
- offset in file (1 based FORTRAN word)- Returns:
- String read
- Throws:
IOException
- problem reading file
-
DM_RSTR
public String DM_RSTR(int isword, int nchar) throws IOException
Read a String- Parameters:
isword
- offset in file (1 based FORTRAN word)nchar
- number of characters to read- Returns:
- String read
- Throws:
IOException
- problem reading file
-
DM_RDTR
public GempakFileReader.RData DM_RDTR(int irow, int icol, String partName) throws IOException
Read the data- Parameters:
irow
- row to readicol
- column to readpartName
- part name- Returns:
- the header and data array or null;
- Throws:
IOException
- problem reading file
-
DM_RDTR
public GempakFileReader.RData DM_RDTR(int irow, int icol, String partName, int decimalScale) throws IOException
Read the real (float) data- Parameters:
irow
- row to readicol
- column to readpartName
- part namedecimalScale
- scaling factor (power of 10);- Returns:
- the header and data array or null;
- Throws:
IOException
- problem reading file
-
DM_UNPK
public float[] DM_UNPK(GempakFileReader.DMPart part, int[] ibitst)
Unpack an array of packed integers.- Parameters:
part
- the part with packing infoibitst
- packed integer bit string- Returns:
- unpacked ints as floats
-
getBits
protected static String getBits(int b)
Get a bit string for an integer- Parameters:
b
- the integer- Returns:
- a bit string (e.g.: 01100001|11000000|10011010|10110100|)
-
DM_RPKG
public float[] DM_RPKG(int isword, int nword, int decimalScale) throws IOException
subclass should implement- Parameters:
isword
- starting word (1 based)nword
- number of words to readdecimalScale
- decimal scale- Returns:
- returns null unless subclass overrides
- Throws:
IOException
- problem reading data
-
-