Package oms3.io
Class DataIO
- java.lang.Object
-
- oms3.io.DataIO
-
public class DataIO extends Object
Data Input/Output management.- Author:
- Olaf David
-
-
Field Summary
Fields Modifier and Type Field Description static intANNUAL_MEANstatic StringCSPROPERTIES_EXTstatic StringCSTABLE_EXTstatic intDAILYstatic StringDATE_ENDstatic StringDATE_FORMATstatic StringDATE_STARTstatic StringHEADERstatic StringHEADER1static StringKEY_CONVERTED_FROMstatic StringKEY_CREATED_ATstatic StringKEY_CREATED_BYstatic StringKEY_DIGESTstatic StringKEY_FC_DAYSstatic StringKEY_FC_STARTstatic StringKEY_FORMATstatic StringKEY_HIST_YEARstatic StringKEY_MISSING_VALstatic StringKEY_NAMEstatic StringKEY_TYPEstatic StringKEY_UNITstatic intMEAN_MONTHLYstatic intMONTHLY_MEANstatic intPERIOD_MAXstatic intPERIOD_MEANstatic intPERIOD_MEDIANstatic intPERIOD_MINstatic intPERIOD_STANDARD_DEVIATIONstatic StringPROPERTIESstatic StringPROPERTIES1static StringPROPERTYstatic StringPROPERTY1static StringTABLEstatic StringTABLE1static StringVAL_DATE
-
Constructor Summary
Constructors Constructor Description DataIO()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CSTableasTable(CSProperties p, String dim)static booleancolumnExist(CSTable table, String name)Check if a column exist in table.static intcolumnIndex(CSTable table, String name)Gets a column index by namestatic int[]columnIndexes(CSTable table, String name)Get the column indexes for a given column name.static List<String>columnNames(CSTable table, String name)static TableModelcreateTableModel(CSTable src)Create a r/o data tablemodelstatic Stringdiff(double[] o, double[] p)static CSTableextractColumns(CSTable table, String... colNames)Extract the columns and create another table.static intfindRowByDate(Date date, int dateColumn, CSTable table)static TableModelfromCSP(CSProperties p, int dim)Returns a r/o table from a CSP filestatic CSPropertiesfromTable(CSTable t)static AbstractTableModelget2DBounded(CSProperties p, String pname)static AbstractTableModelgetBoundProperties(CSProperties p, String boundName)static Date[]getColumnDateValues(CSTable t, String columnName)static Double[]getColumnDoubleValues(CSTable t, String columnName)Get a column as an int array.static double[]getColumnDoubleValuesInterval(Date start, Date end, CSTable t, String columnName, int timeStep)static DategetDate(CSProperties p, String key)Get a value as date.static intgetInt(CSProperties p, String key)Get a value as integer.static AbstractTableModelgetProperties(CSProperties p)Get the KVP as table.static CSTablegetTable(CSProperties p, String boundName)static AbstractTableModelgetUnBoundProperties(CSProperties p)static booleanisBound(CSProperties p, String key, int dim)static List<String>keysByMeta(CSProperties csp, String mkey, String mval)static List<String>keysByNotMeta(CSProperties csp, String mkey)static List<String>keysForBounds(CSProperties csp, int boundCount)static SimpleDateFormatlookupDateFormat(CSTable table, int col)static voidmain(String[] args)static voidmerge(CSProperties base, CSProperties overlay)Merges two Properties, respects permissionsstatic booleanplaysRole(CSProperties p, String key, String role)static voidprint(Map<String,Object> props, String header, PrintWriter out)static voidprint(CSProperties props, PrintWriter out)Print CSProperties.static voidprint(CSTable table, PrintWriter out)Print a CSTable to a PrintWriterstatic CSPropertiesproperties()Create Empty propertiesstatic List<String>properties(File f)Find all properties section names in a file.static CSPropertiesproperties(Reader[] r, String name)Create a CSProperty from an array of reader.static CSPropertiesproperties(Reader r, String name)Parse properties from a readerstatic CSPropertiesproperties(Map<String,Object> p)Convert from a Map to properties.static CSPropertiesproperties(Properties p)Convert Properties to CSProperties.static Propertiesproperties(CSProperties p)Convert CSProperties into Propertiesstatic double[]rowDoubleValues(String[] row, int[] idx)static double[]rowDoubleValues(String[] row, int[] idx, double[] vals)static voidrowStringValues(String[] row, int[] idx, String[] vals)static voidsave(CSProperties csp, File f, String title)static voidsave(CSTable table, File file)Saves a table to a file.static int[]sliceByTime(CSTable table, int timeCol, Date start, Date end)Get a slice of rows out of the table matching the time windowstatic CSTablesynthESPInput(CSTable table, Date iniStart, Date iniEnd, int fcDays, int year)static CSTabletable(File file)Parse the first table from a filestatic CSTabletable(File file, String name)Parse a table from a given File.static CSTabletable(String s)Parse a table from a Reader.static CSTabletable(String s, String name)Parse a table from a Reader.static CSTabletable(URL url)Opens the first table found at the URLstatic CSTabletable(URL url, String name)Create a CSTable from a URL source.static List<String>tables(File f)Find all table names in a file.static StringtoArrayString(String[] arr)Create array string.static StringtoArrayString(String[][] arr)
-
-
-
Field Detail
-
TABLE
public static final String TABLE
- See Also:
- Constant Field Values
-
HEADER
public static final String HEADER
- See Also:
- Constant Field Values
-
PROPERTIES
public static final String PROPERTIES
- See Also:
- Constant Field Values
-
PROPERTY
public static final String PROPERTY
- See Also:
- Constant Field Values
-
TABLE1
public static final String TABLE1
- See Also:
- Constant Field Values
-
HEADER1
public static final String HEADER1
- See Also:
- Constant Field Values
-
PROPERTIES1
public static final String PROPERTIES1
- See Also:
- Constant Field Values
-
PROPERTY1
public static final String PROPERTY1
- See Also:
- Constant Field Values
-
CSPROPERTIES_EXT
public static final String CSPROPERTIES_EXT
- See Also:
- Constant Field Values
-
CSTABLE_EXT
public static final String CSTABLE_EXT
- See Also:
- Constant Field Values
-
KEY_CONVERTED_FROM
public static final String KEY_CONVERTED_FROM
- See Also:
- Constant Field Values
-
DATE_FORMAT
public static final String DATE_FORMAT
- See Also:
- Constant Field Values
-
DATE_START
public static final String DATE_START
- See Also:
- Constant Field Values
-
DATE_END
public static final String DATE_END
- See Also:
- Constant Field Values
-
KEY_CREATED_AT
public static final String KEY_CREATED_AT
- See Also:
- Constant Field Values
-
KEY_CREATED_BY
public static final String KEY_CREATED_BY
- See Also:
- Constant Field Values
-
KEY_UNIT
public static final String KEY_UNIT
- See Also:
- Constant Field Values
-
KEY_FORMAT
public static final String KEY_FORMAT
- See Also:
- Constant Field Values
-
KEY_TYPE
public static final String KEY_TYPE
- See Also:
- Constant Field Values
-
KEY_NAME
public static final String KEY_NAME
- See Also:
- Constant Field Values
-
KEY_MISSING_VAL
public static final String KEY_MISSING_VAL
- See Also:
- Constant Field Values
-
KEY_FC_START
public static final String KEY_FC_START
- See Also:
- Constant Field Values
-
KEY_FC_DAYS
public static final String KEY_FC_DAYS
- See Also:
- Constant Field Values
-
KEY_HIST_YEAR
public static final String KEY_HIST_YEAR
- See Also:
- Constant Field Values
-
KEY_DIGEST
public static final String KEY_DIGEST
- See Also:
- Constant Field Values
-
VAL_DATE
public static final String VAL_DATE
- See Also:
- Constant Field Values
-
DAILY
public static final int DAILY
- See Also:
- Constant Field Values
-
MEAN_MONTHLY
public static final int MEAN_MONTHLY
- See Also:
- Constant Field Values
-
MONTHLY_MEAN
public static final int MONTHLY_MEAN
- See Also:
- Constant Field Values
-
ANNUAL_MEAN
public static final int ANNUAL_MEAN
- See Also:
- Constant Field Values
-
PERIOD_MEAN
public static final int PERIOD_MEAN
- See Also:
- Constant Field Values
-
PERIOD_MEDIAN
public static final int PERIOD_MEDIAN
- See Also:
- Constant Field Values
-
PERIOD_STANDARD_DEVIATION
public static final int PERIOD_STANDARD_DEVIATION
- See Also:
- Constant Field Values
-
PERIOD_MIN
public static final int PERIOD_MIN
- See Also:
- Constant Field Values
-
PERIOD_MAX
public static final int PERIOD_MAX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getColumnDoubleValuesInterval
public static double[] getColumnDoubleValuesInterval(Date start, Date end, CSTable t, String columnName, int timeStep)
-
lookupDateFormat
public static SimpleDateFormat lookupDateFormat(CSTable table, int col)
-
synthESPInput
public static CSTable synthESPInput(CSTable table, Date iniStart, Date iniEnd, int fcDays, int year)
-
sliceByTime
public static int[] sliceByTime(CSTable table, int timeCol, Date start, Date end)
Get a slice of rows out of the table matching the time window- Parameters:
table-timeCol-start-end-- Returns:
- the first and last row that matches the time window start->end
-
createTableModel
public static TableModel createTableModel(CSTable src)
Create a r/o data tablemodel- Parameters:
src-- Returns:
- a table model to the CSTable
-
getProperties
public static AbstractTableModel getProperties(CSProperties p)
Get the KVP as table.- Parameters:
p-- Returns:
- an AbstractTableModel for properties (KVP)
-
get2DBounded
public static AbstractTableModel get2DBounded(CSProperties p, String pname) throws ParseException
- Throws:
ParseException
-
playsRole
public static boolean playsRole(CSProperties p, String key, String role)
-
isBound
public static boolean isBound(CSProperties p, String key, int dim)
-
getTable
public static CSTable getTable(CSProperties p, String boundName)
-
getBoundProperties
public static AbstractTableModel getBoundProperties(CSProperties p, String boundName) throws ParseException
- Throws:
ParseException
-
getUnBoundProperties
public static AbstractTableModel getUnBoundProperties(CSProperties p) throws ParseException
- Throws:
ParseException
-
toArrayString
public static String toArrayString(String[] arr)
Create array string.- Parameters:
arr-- Returns:
- an array String.
-
fromCSP
public static TableModel fromCSP(CSProperties p, int dim)
Returns a r/o table from a CSP file- Parameters:
p-dim-- Returns:
- a table model for properties with dimension.
-
keysByMeta
public static List<String> keysByMeta(CSProperties csp, String mkey, String mval)
- Parameters:
csp-mkey-mval-- Returns:
- the list of property keys that have a meta data value.
-
keysForBounds
public static List<String> keysForBounds(CSProperties csp, int boundCount)
-
keysByNotMeta
public static List<String> keysByNotMeta(CSProperties csp, String mkey)
-
getColumnDoubleValues
public static Double[] getColumnDoubleValues(CSTable t, String columnName)
Get a column as an int array.- Parameters:
t-columnName-- Returns:
- the column data as doubles.
-
getDate
public static Date getDate(CSProperties p, String key) throws ParseException
Get a value as date.- Parameters:
p-key-- Returns:
- a property as Date
- Throws:
ParseException
-
getInt
public static int getInt(CSProperties p, String key) throws ParseException
Get a value as integer.- Parameters:
p-key-- Returns:
- a property value as integer.
- Throws:
ParseException
-
save
public static void save(CSProperties csp, File f, String title)
-
print
public static void print(CSProperties props, PrintWriter out)
Print CSProperties.- Parameters:
props- the Properties to printout- the output writer to print to.
-
print
public static void print(Map<String,Object> props, String header, PrintWriter out)
-
print
public static void print(CSTable table, PrintWriter out)
Print a CSTable to a PrintWriter- Parameters:
table- the table to printout- the writer to write to
-
save
public static void save(CSTable table, File file) throws IOException
Saves a table to a file.- Parameters:
table- the table to savefile- the file to store it in (overwritten, if exists)- Throws:
IOException
-
properties
public static CSProperties properties(Reader r, String name) throws IOException
Parse properties from a reader- Parameters:
r- the Readername- the name of the properties- Returns:
- properties from a file.
- Throws:
IOException
-
properties
public static CSProperties properties(Reader[] r, String name) throws IOException
Create a CSProperty from an array of reader.- Parameters:
r-name-- Returns:
- merged properties.
- Throws:
IOException
-
merge
public static void merge(CSProperties base, CSProperties overlay)
Merges two Properties, respects permissions- Parameters:
base-overlay-
-
properties
public static Properties properties(CSProperties p)
Convert CSProperties into Properties- Parameters:
p-- Returns:
- the Properties.
-
properties
public static CSProperties properties(Properties p)
Convert Properties to CSProperties.- Parameters:
p- the Properties- Returns:
- CSProperties
-
properties
public static CSProperties properties(Map<String,Object> p)
Convert from a Map to properties.- Parameters:
p- the source map- Returns:
- CSProperties
-
properties
public static CSProperties properties()
Create Empty properties- Returns:
- get some empty properties.
-
table
public static CSTable table(File file) throws IOException
Parse the first table from a file- Parameters:
file- the file to parse- Returns:
- the CSTable
- Throws:
IOException
-
table
public static CSTable table(File file, String name) throws IOException
Parse a table from a given File.- Parameters:
file-name-- Returns:
- a CSTable.
- Throws:
IOException
-
table
public static CSTable table(String s) throws IOException
Parse a table from a Reader. Find the first table- Parameters:
s- the Reader to read from- Returns:
- the CSTable
- Throws:
IOException
-
table
public static CSTable table(String s, String name) throws IOException
Parse a table from a Reader.- Parameters:
s- the Reader to read fromname- the name of the table- Returns:
- the CSTable
- Throws:
IOException
-
table
public static CSTable table(URL url) throws IOException
Opens the first table found at the URL- Parameters:
url- the URL- Returns:
- the CSTable
- Throws:
IOException
-
table
public static CSTable table(URL url, String name) throws IOException
Create a CSTable from a URL source.- Parameters:
url- the table URLname- the name of the table- Returns:
- a new CSTable
- Throws:
IOException
-
columnExist
public static boolean columnExist(CSTable table, String name)
Check if a column exist in table.- Parameters:
table- the table to checkname- the name of the column- Returns:
-
columnIndex
public static int columnIndex(CSTable table, String name)
Gets a column index by name- Parameters:
table- The table to checkname- the column name- Returns:
- the index of the column
-
columnIndexes
public static int[] columnIndexes(CSTable table, String name)
Get the column indexes for a given column name. (e.g. use tmin to fetch tmin[0], tmin[1]...)- Parameters:
table-name-- Returns:
-
rowDoubleValues
public static double[] rowDoubleValues(String[] row, int[] idx, double[] vals)
-
rowDoubleValues
public static double[] rowDoubleValues(String[] row, int[] idx)
-
extractColumns
public static CSTable extractColumns(CSTable table, String... colNames)
Extract the columns and create another table.- Parameters:
table- the tablecolName- the names of the columns to extract.- Returns:
- A new Table with the Columns.
-
diff
public static String diff(double[] o, double[] p)
-
asTable
public static CSTable asTable(CSProperties p, String dim)
-
fromTable
public static CSProperties fromTable(CSTable t)
-
tables
public static List<String> tables(File f) throws IOException
Find all table names in a file.- Parameters:
f- the file to search in- Returns:
- a list of table names found in that file.
- Throws:
IOException
-
properties
public static List<String> properties(File f) throws IOException
Find all properties section names in a file.- Parameters:
f- the file to search in- Returns:
- a list of section names found in that file.
- Throws:
IOException
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
-