visad.data.text
Class TextAdapter
- java.lang.Object
-
- visad.data.text.TextAdapter
-
public class TextAdapter extends java.lang.Objectthis is an VisAD file adapter for comma-, tab- and blank-separated ASCII text file data. It will attempt to create a FlatField from the data and descriptions given in the file and/or the constructor. The text files contained delimited data. The delimiter is determined as follows: if the file has a well-known extension (.csv, .tsv, .bsv) then the delimiter is implied by the extension. In all other cases, the delimiter for the data (and for the "column labels") is determined by reading the first line and looking, in order, for a tab, comma, or blank. Which ever one is found first is taken as the delimiter. Two extra pieces of information are needed: the VisAD "MathType" which is specified as a string (e.g., (x,y)->(temperature)) and may either be the first line of the file or passed in through one of the constructors. The second item are the "column labels" which contain the names of each field in the data. The names of all range components specified in the "MathType" must appear. The names of domain components are optional. The values in this string are separated by the delimiter, as defined above. See visad.data.text.README.text for more details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static interfaceTextAdapter.DateParserused to allow applications to define their own date parsingstatic interfaceTextAdapter.StreamProcessor
-
Constructor Summary
Constructors Constructor and Description TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, boolean onlyReadOneLine)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine, java.lang.String skipPatternString)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine, java.lang.String skipPatternString, TextAdapter.StreamProcessor streamProcessor)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.lang.String filename)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.lang.String filename, java.lang.String map, java.lang.String params)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.net.URL url)Create a VisAD FlatField from a remote Text (comma-, tab- or blank-separated values) ASCII fileTextAdapter(java.net.URL url, java.lang.String map, java.lang.String params)Create a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static voidaddDateParser(TextAdapter.DateParser dateParser)used to allow applications to define their own date parsingstatic doubledecodeLatLon(java.lang.String latlon)A cut-and-paste from the IDV Misc method Decodes a string representation of a latitude or longitude and returns a double version (in degrees).FieldgetData()get the datastatic java.lang.StringgetDelimiter(java.lang.String filename)static booleanisComment(java.lang.String line)Is the given text line a commentstatic voidmain(java.lang.String[] args)static DataprocessFile(java.lang.String file)Read in the given file and return the processed datastatic java.lang.StringreadLine(java.io.BufferedReader bis)
-
-
-
Constructor Detail
-
TextAdapter
public TextAdapter(java.lang.String filename) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
filename- name of local file.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.lang.String filename, java.lang.String map, java.lang.String params) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
filename- name of local file.map- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.net.URL url) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a remote Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
url- File URL.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.net.URL url, java.lang.String map, java.lang.String params) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
url- File URL.map- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
inputStream- The input stream to read fromdelimiter- the delimitermap- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, boolean onlyReadOneLine) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
inputStream- The input stream to read fromdelimiter- the delimitermap- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.onlyReadOneLine- If true then only read one line of data. This is used so client code can read the meta data.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
inputStream- The input stream to read fromdelimiter- the delimitermap- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.properties- propertiesonlyReadOneLine- If true then only read one line of data. This is used so client code can read the meta data.- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine, java.lang.String skipPatternString) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
inputStream- The input stream to read fromdelimiter- the delimitermap- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.properties- propertiesonlyReadOneLine- If true then only read one line of data. This is used so client code can read the meta data.skipPatternString- if non-null then skip any line that matches this pattern- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
TextAdapter
public TextAdapter(java.io.InputStream inputStream, java.lang.String delimiter, java.lang.String map, java.lang.String params, java.util.Hashtable properties, boolean onlyReadOneLine, java.lang.String skipPatternString, TextAdapter.StreamProcessor streamProcessor) throws java.io.IOException, VisADExceptionCreate a VisAD FlatField from a local Text (comma-, tab- or blank-separated values) ASCII file- Parameters:
inputStream- The input stream to read fromdelimiter- the delimitermap- the VisAD "MathType" as a string defining the FlatFieldparams- the list of parameters used to define what columns of the text file correspond to what MathType parameters.properties- propertiesonlyReadOneLine- If true then only read one line of data. This is used so client code can read the meta data.skipPatternString- if non-null then skip any line that matches this patternstreamProcessor- Optional processor of the Tuple stream for point obs- Throws:
java.io.IOException- if there was a problem reading the file.VisADException- if an unexpected problem occurs.
-
-
Method Detail
-
getDelimiter
public static java.lang.String getDelimiter(java.lang.String filename)
-
isComment
public static boolean isComment(java.lang.String line)
Is the given text line a comment- Returns:
- is it a comment line
-
readLine
public static java.lang.String readLine(java.io.BufferedReader bis) throws java.io.IOException- Throws:
java.io.IOException
-
addDateParser
public static void addDateParser(TextAdapter.DateParser dateParser)
used to allow applications to define their own date parsing
-
getData
public Field getData()
get the data- Returns:
- a Field of the data read from the file
-
processFile
public static Data processFile(java.lang.String file) throws java.lang.Exception
Read in the given file and return the processed data- Parameters:
file- The file to read in- Returns:
- the data
- Throws:
java.lang.Exception
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
decodeLatLon
public static double decodeLatLon(java.lang.String latlon)
A cut-and-paste from the IDV Misc method Decodes a string representation of a latitude or longitude and returns a double version (in degrees). Acceptible formats are:+/- ddd:mm, ddd:mm:, ddd:mm:ss, ddd::ss, ddd.fffff ===> [+/-] ddd.fffff +/- ddd, ddd:, ddd:: ===> [+/-] ddd +/- :mm, :mm:, :mm:ss, ::ss, .fffff ===> [+/-] .fffff +/- :, :: ===> 0.0 Any of the above with N,S,E,W appended
- Parameters:
latlon- string representation of lat or lon- Returns:
- the decoded value in degrees
-
-
DMelt 3.0 © DataMelt by jWork.ORG