Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmerz committed Nov 13, 2015
2 parents 299b7f8 + 6b6ae6b commit bb04892
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion export/java/src/edu/ucdavis/watershed/CMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void main(String[] args) throws Exception {

for( Config config: input.getData() ) {
CsvData data = Csv.parseCsv(config.getCsvFilePath(), config.getType());
Dss.write(config, data, dssFile);
Dss.write(config, data, dssFile, input.getPath());
}

//} catch (Exception e) {
Expand Down
18 changes: 12 additions & 6 deletions export/java/src/edu/ucdavis/watershed/CsvData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ public void add(CSVRecord record, String type) {
recordData.name = itr.next();
}
} else {
recordData.data.push(Double.parseDouble(itr.next()));
recordData.data.add(Double.parseDouble(itr.next()));
}
i++;
}

data.push(recordData);
data.add(recordData);
}

public void complete(String type) {
columns = new double[data.size()-1][];
columns = new double[data.size()][];

for( int i = 0; i < data.get(0).data.size(); i++ ) {
double[] t = new double[data.size()-1];
double[] t = new double[data.size()];

for( int j = 0; j < data.size(); j++ ) {
t[j] = data.get(j).data.get(i);
try {
t[j] = data.get(j).data.get(i);
} catch (Exception e) {
int k = 1;
}

}

columns[i] = t;
Expand All @@ -50,7 +55,8 @@ public void complete(String type) {
if( type.equals("paired") ) {
firstColumn = new double[data.size()];
for( int i = 0; i < data.size(); i++ ) {
firstColumn[i] = Double.parseDouble(data.get(i).name);
//firstColumn[i] = Double.parseDouble(data.get(i).name);
firstColumn[i] = data.get(i).nameDouble;
}
}
}
Expand Down
62 changes: 35 additions & 27 deletions export/java/src/edu/ucdavis/watershed/Dss.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

import java.util.Date;

import hec.data.meta.Catalog;
import hec.dssgui.CombinedDataManager;
import hec.heclib.dss.HecDSSUtilities;
import hec.heclib.dss.HecDss;
import hec.io.PairedDataContainer;
import hec.io.TimeSeriesContainer;

public class Dss {

@SuppressWarnings("deprecation")
public static Date EPOCH = new Date(1900, 0, 0);

public static HecDss open(String file) throws Exception {
return HecDss.open(file);
}

public static void write(Config config, CsvData data, HecDss dssFile) throws Exception {
public static void write(Config config, CsvData data, HecDss dssFile, String file) throws Exception {
if( config.getType().equals("paired") ) {
writePairedData(config, data, dssFile);
} else {
writeTimeSeriesData(config, data, dssFile);
writeTimeSeriesData(config, data, dssFile, file);
}
}

Expand Down Expand Up @@ -75,45 +81,47 @@ public static void writePairedData(Config config, CsvData data, HecDss dssFile)
dssFile.put(pdc);
}

public static void writeTimeSeriesData(Config config, CsvData csv, HecDss dssFile) throws Exception {
public static void writeTimeSeriesData(Config config, CsvData csv, HecDss dssFile, String file) throws Exception {
TimeSeriesContainer ts = new TimeSeriesContainer();

ts.fullName = config.path;
ts.fileName = file;

ts.fileName = config.path;

ts.startTime = parseTime(csv.data.get(0).name);
ts.endTime = parseTime(csv.data.get(csv.data.size()-1).name);
ts.times = new int[csv.data.size()];
for( int i = 0; i < csv.data.size(); i++ ) {
ts.times[i] = calcTime(csv.data.get(i).name);
}
ts.startTime = ts.times[0];
ts.endTime = ts.times[ts.times.length-1];

ts.values = csv.columns[0];
ts.numberValues = ts.values.length;

// Approx hrs in a month
// you shouldn't need to set this!
ts.interval = config.getInterval();
if( config.getParameter() != null ) {
ts.parameter = config.getParameter(); //partE;
}

int[] quality = new int[config.getQuality().size()];
for( int i = 0; i < quality.length; i++ ) {
quality[i] = config.getQuality().get(i);
if( config.getLocation() != null ) {
ts.location = config.getLocation(); //partE;
}
ts.quality = quality;

ts.subLocation = config.getSubLocation();
ts.subParameter = config.getSubParameter();
ts.timeZoneID = config.getTimeZoneID();
ts.timeZoneRawOffset = config.getTimeZoneRawOffset();


ts.type = config.getXtype();
ts.units = config.getUnits();

dssFile.put(ts);
}

public static int parseTime(String datestring) {
String[] parts = datestring.split("-");
Date d = new Date(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
@SuppressWarnings("deprecation")
public static int calcTime(String date) {
String[] parts = date.split("-");

// we want to store in minutes
long t = d.getTime() / ((long)1000 * (long)60);
int year = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
int day = Integer.parseInt(parts[2]);

return (int) t;
Date d = new Date(year, month, day);
long diff = d.getTime() - EPOCH.getTime();
diff = diff / (1000 * 60);
return (int) diff;
}

}
Expand Down

0 comments on commit bb04892

Please sign in to comment.