forked from lidi100/MeteoInfoLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wyq
committed
Sep 21, 2014
1 parent
b04eaef
commit f0d5859
Showing
16 changed files
with
582 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
build.xml.data.CRC32=7803fa5b | ||
build.xml.script.CRC32=7dae9224 | ||
build.xml.stylesheet.CRC32=28e38971@1.56.1.46 | ||
build.xml.script.CRC32=eae44caa | ||
build.xml.stylesheet.CRC32=8064a381@1.75.1.48 | ||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
nbproject/build-impl.xml.data.CRC32=7803fa5b | ||
nbproject/build-impl.xml.script.CRC32=0a089983 | ||
nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 | ||
nbproject/build-impl.xml.script.CRC32=fc068241 | ||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.1.48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.meteoinfo.data; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.swing.JOptionPane; | ||
import org.meteoinfo.data.mapdata.Field; | ||
import org.meteoinfo.global.MIMath; | ||
import org.meteoinfo.global.table.DataColumn; | ||
import org.meteoinfo.global.table.DataRow; | ||
import org.meteoinfo.global.table.DataTable; | ||
import org.meteoinfo.global.table.DataTypes; | ||
import org.meteoinfo.global.util.GlobalUtil; | ||
|
||
/** | ||
* | ||
* @author wyq | ||
*/ | ||
public class TimeSeriesData { | ||
|
||
// <editor-fold desc="Variables"> | ||
private DataTable dataTable = new DataTable(); | ||
|
||
// </editor-fold> | ||
// <editor-fold desc="Constructor"> | ||
/** | ||
* Constructor | ||
*/ | ||
public TimeSeriesData() { | ||
DataColumn col = new DataColumn("Time", DataTypes.Date); | ||
dataTable.addColumn(col); | ||
} | ||
|
||
// </editor-fold> | ||
// <editor-fold desc="Get Set Methods"> | ||
/** | ||
* Get data table | ||
* | ||
* @return Data table | ||
*/ | ||
public DataTable getDataTable() { | ||
return dataTable; | ||
} | ||
|
||
// </editor-fold> | ||
// <editor-fold desc="Methods"> | ||
/** | ||
* Add column | ||
* | ||
* @param col The column | ||
*/ | ||
public void addColumn(DataColumn col) { | ||
dataTable.addColumn(col); | ||
} | ||
|
||
/** | ||
* Add column | ||
* | ||
* @param colName Column name | ||
* @param dataType Data type | ||
*/ | ||
public void addColumn(String colName, DataTypes dataType) { | ||
try { | ||
dataTable.addColumn(colName, dataType); | ||
} catch (Exception ex) { | ||
Logger.getLogger(TimeSeriesData.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
/** | ||
* Add data row | ||
*/ | ||
public void addRow() { | ||
try { | ||
dataTable.addRow(); | ||
} catch (Exception ex) { | ||
Logger.getLogger(TimeSeriesData.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
/** | ||
* Add data row | ||
* | ||
* @param row Data row | ||
*/ | ||
public void addRow(DataRow row) { | ||
try { | ||
dataTable.addRow(row); | ||
} catch (Exception ex) { | ||
Logger.getLogger(TimeSeriesData.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
/** | ||
* Read data table from ASCII file | ||
* | ||
* @param fileName File name | ||
* @param timeColIdx Time column index | ||
* @param formatStr Time format string | ||
* @throws java.io.FileNotFoundException | ||
*/ | ||
public void readASCIIFile(String fileName, int timeColIdx, String formatStr) throws FileNotFoundException, IOException, Exception { | ||
DataTable dTable = new DataTable(); | ||
dTable.addColumn("Time", DataTypes.Date); | ||
|
||
BufferedReader sr = new BufferedReader(new FileReader(new File(fileName))); | ||
String title = sr.readLine().trim(); | ||
//Determine separator | ||
String separator = GlobalUtil.getSeparator(title); | ||
String[] titleArray = GlobalUtil.split(title, separator); | ||
if (titleArray.length <= 2) { | ||
JOptionPane.showMessageDialog(null, "File Format Error!"); | ||
sr.close(); | ||
} else { | ||
//Get fields | ||
String line = sr.readLine().trim(); //Second line | ||
String[] dataArray = GlobalUtil.split(line, separator); | ||
if (dataArray.length != titleArray.length) { | ||
JOptionPane.showMessageDialog(null, "File Format Error!"); | ||
sr.close(); | ||
return; | ||
} | ||
SimpleDateFormat format = new SimpleDateFormat(formatStr); | ||
List<Integer> dataIdxs = new ArrayList<Integer>(); | ||
String fieldName; | ||
DataTypes dataType; | ||
int rn = 0; | ||
for (int i = 0; i < dataArray.length; i++) { | ||
fieldName = titleArray[i]; | ||
if (i == timeColIdx) { | ||
dTable.getColumns().get(0).setColumnName(fieldName); | ||
continue; | ||
} | ||
if (MIMath.isNumeric(dataArray[i])) { | ||
dataType = DataTypes.Double; | ||
dTable.addColumn(fieldName, dataType); | ||
dataIdxs.add(i); | ||
} | ||
} | ||
dTable.addRow(); | ||
dTable.setValue(rn, 0, format.parse(dataArray[timeColIdx])); | ||
int cn = 0; | ||
for (int idx : dataIdxs) { | ||
dTable.setValue(rn, cn, Double.parseDouble(dataArray[idx])); | ||
cn++; | ||
} | ||
|
||
rn += 1; | ||
line = sr.readLine(); | ||
while (line != null) { | ||
line = line.trim(); | ||
if (line.isEmpty()) { | ||
continue; | ||
} | ||
dataArray = GlobalUtil.split(line, separator); | ||
dTable.addRow(); | ||
dTable.setValue(rn, 0, format.parse(dataArray[timeColIdx])); | ||
cn = 0; | ||
for (int idx : dataIdxs) { | ||
dTable.setValue(rn, cn, Double.parseDouble(dataArray[idx])); | ||
cn++; | ||
} | ||
|
||
rn += 1; | ||
line = sr.readLine(); | ||
} | ||
|
||
dataTable = dTable; | ||
sr.close(); | ||
} | ||
} | ||
|
||
/** | ||
* Get average data table | ||
* @return Average data table | ||
*/ | ||
public DataTable average(){ | ||
DataTable rTable = new DataTable(); | ||
for (DataColumn col : dataTable.getColumns()){ | ||
DataColumn ncol = new DataColumn(col.getColumnName(), col.getDataType()); | ||
rTable.addColumn(ncol); | ||
} | ||
|
||
return rTable; | ||
} | ||
|
||
// </editor-fold> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.