Time series data is retrieved from DSS using a TimeSeriesContainer along with a valid pathname and time window. The time window can either be implicit or explicit. An implicit time window generally indicates that you want to read all the data in a single record.

For example, if you have a pathname like "/A/B/C/01Jan2005/1Day/F/", with no other time window given, that would imply to read all the data for the year 2005 (365 values). An explicit time window can be specified in the TimeSeriesContainer parameters "startTime" and "endTime", or in the D part of the pathname.

Another way an explicit time window can be provided is by giving the date span in the D part, similar to a "condensed catalog" pathname is. This method has the start date followed by " – " (space, dash, space) and then the end date. For example:
"/A/B/C/22Jan2005 – 17Mar2012/1Day/F/"

Will read all the data from the start of the day on 22Jan2005 through the end of the day on 17Mar2012. This method is mainly for convenience when you already have a condensed pathname; using the start time and end time in the time series container is preferred.


You must also have the exact time interval (E part) and other pathname parts. If you do not have a full complete pathname, or a time window, then you can search the DSS file for pathnames that meet your criteria. See the catalog section for more information.
Time series data is retrieved using the HecTimeSeries function "read":

public int read (TimeSeriesContainer timeSeriesContainer, boolean trimMissing);
JAVA



HecTimeSeries. read() returns 0 (zero) for a successful operation. If an error occurred, a negative number is returned. See the section on error processing for more information.
The "trimMissing" flag indicates if leading and trailing missing data flags should be removed.

The start and end times will be updated to reflect the missing flag removal.
Regular interval data does not normally contain a time array, but if you request it, it will be generated.
After retrieval, use the following TimeSeriesContainer functions to get data and times:

public double[] getValues()
public HecTimeArray getTimes()
JAVA


See the documentation on time series containers for other information that can be obtained.



Example: Basic storage and retrieval of regular-interval time series data

import javax.swing.UIManager;

import hec.heclib.dss.*;
import hec.heclib.util.HecTime;
import hec.heclib.util.HecTimeArray;
import hec.io.TimeSeriesContainer;

//  A simple snippet of code to demonstrate storing and retrieving 
//  regular-interval time series data
//  For a complete proper example, see SampleTimeSeriesComplete
//
public class ExampleTimeSeries1 {

	public static void main (String args[])  {

		try {
			javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception ignore) {}
		
		//  Write a regular interval data set.  Gen up the data
		TimeSeriesContainer tsc = new TimeSeriesContainer();		
		double[] values = new double[200];
		for (int i=0; i<200; i++) {
			values[i] = (double)i / 3.0;
		}
		tsc.setValues(values);
		tsc.setName("/Basin/Location/Flow//1Hour/Java Sample/");
		HecTime hecTime = new HecTime("20Jan2010", "1230");
		tsc.setStartTime(hecTime);		
		tsc.setUnits("CFS");
		tsc.setType("Inst-Val");
		
		HecTimeSeries dssTimeSeries = new HecTimeSeries();
		dssTimeSeries.setDSSFileName("C:/temp/Example7.dss");
		//  If you have issues, show user debug info
//  dssTimeSeries.zsetMessageLevel(HecDataManager.MESS_METHOD_GLOBAL, 
//									 HecDataManager.MESS_LEVEL_USER_DIAG);   
		int status = dssTimeSeries.write(tsc);
		dssTimeSeries.done();		
		if (status != 0) return;
		
		//  Read data
		TimeSeriesContainer tscRead = new TimeSeriesContainer();
		//  Note - implicit time window given using D and E parts.
		//  A time window must be provided and there are several alternatives for doing this
		tscRead.setName("/Basin/Location/Flow/01Jan2010/1Hour/Java Sample/");
		HecTimeSeries dssTimeSeriesRead = new HecTimeSeries();
		dssTimeSeriesRead.setDSSFileName("C:/temp/Example7.dss");
		status = dssTimeSeriesRead.read(tscRead, true);
		dssTimeSeriesRead.done();		
		if (status != 0) return;
		HecTimeArray hTimes = tscRead.getTimes();
		double vals[] = tscRead.getValues();
		for (int i=0; i<tscRead.numberValues; i++) {			
			System.out.println("Ordinate: " + i + ", time: " + hTimes.element(i).dateAndTime() + 
					", value: " + vals[i]);
		}
		HecDataManager.closeAllFiles();  //  Only at the end of the program
	}
}

JAVA


Example: Storage and retrieval of irregular-interval time series data

import javax.swing.UIManager;
import hec.heclib.dss.*;
import hec.heclib.util.HecTime;
import hec.heclib.util.HecTimeArray;
import hec.io.TimeSeriesContainer;

//  A simple snippit of code to demonstrate storing and retrieving 
//  irregular-interval time series data
//
public class ExampleTimeSeries2 {

	public static void main (String args[])  {

		try {
			javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception ignore) {}
		
		//  Write a irregular interval data set.  Gen up the data and times
		double values[] = new double[200];
		//  Irregular interval data requires the times array
		HecTimeArray times = new HecTimeArray(200);
		HecTime hecTime = new HecTime("20Jan2010", "1200");
		for (int i=0; i<200; i++) {
			values[i] = (double)i;
			//  Make it irregular by adding 10 min for even, subtracting for odd
			if (i % 2 == 0) {
				hecTime.addMinutes(60 + 10);
			}
			else {
				hecTime.addMinutes(60 - 10);
			}
			times.setElementAt(new HecTime(hecTime), i);
		}
		TimeSeriesContainer tsc = new TimeSeriesContainer();
		tsc.set(values, times);
		tsc.setName("/Basin/Location/Flow//Ir-Month/Java Example 2/");		
		tsc.setUnits("CFS");
		tsc.setType("Inst-Val");
		
		HecTimeSeries dssTimeSeries = new HecTimeSeries();
		dssTimeSeries.setDSSFileName("C:/temp/Example7.dss");		
		int status = dssTimeSeries.write(tsc);
		dssTimeSeries.done();		
		if (status != 0) return;
		
		//  Read data
		TimeSeriesContainer tscRead = new TimeSeriesContainer();		
		tscRead.setName("/Basin/Location/Flow//Ir-Month/Java Example 2/");
		tscRead.setStartTime(new HecTime("01Jan2010", "0001"));
		tscRead.setEndTime(new HecTime("31Jan2010", "2400"));
		HecTimeSeries dssTimeSeriesRead = new HecTimeSeries();
		dssTimeSeriesRead.setDSSFileName("C:/temp/Example7.dss");		
		status = dssTimeSeriesRead.read(tscRead, false);
		dssTimeSeriesRead.done();		
		if (status != 0) return;
		HecTimeArray hTimes = tscRead.getTimes();
		double vals[] = tscRead.getValues();
		for (int i=0; i<vals.length; i++) {			
			System.out.println("Ordinate: " + i + ", time: " + hTimes.element(i).dateAndTime() + 
					", value: " + vals[i]);
		}
		HecDataManager.closeAllFiles();
	}
}
JAVA



 Example: Retrieve Period-Of-Record data and plot without time window

import java.util.Vector;
import javax.swing.UIManager;

import hec.dataTable.HecDataTableFrame;
import hec.gfx2d.G2dDialog;
import hec.heclib.dss.*;
import hec.io.DataContainer;
import hec.io.TimeSeriesContainer;

//  Get all data (period of record) for a dataset in a DSS file
//  We don't know the time window
public class ExampleTimeSeries3 {

	public static void main (String args[])  {

		try {
			javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception ignore) {}
		
		//  In the example DSS file from HEC-DSSVue, there is period of record 
		//  precip and temperature.  
		//  Get the max temperature for POR and plot it.
		//  We don't know when it stops or ends, so use POR flag
		TimeSeriesContainer tsc = new TimeSeriesContainer();		
		tsc.setName("//SACRAMENTO/TEMP-MAX/01JAN1980/1DAY/OBS/");
		tsc.retrieveAllTimes = true;
		HecTimeSeries dssTimeSeries = new HecTimeSeries();
		//  This is the "sample.dss" file included with HEC-DSSVue, converted to version 7
		dssTimeSeries.setDSSFileName("C:/temp/Sample7.dss");
		//  If you have issues, show user debug info
		//  dssTimeSeries.zsetMessageLevel(HecDataManager.MESS_METHOD_GLOBAL, 
		//									 HecDataManager.MESS_LEVEL_USER_DIAG);
		int status = dssTimeSeries.read(tsc, true);
		dssTimeSeries.done();		
		if (status != 0) return;

		//  Show in a plot
		Vector<DataContainer> v = new Vector<DataContainer>();
		v.add(tsc);
		hec.gfx2d.G2dDialog plot =  new G2dDialog(null, "My Plot", false, v);
		plot.setVisible(true);

		//  Show in a table
		 HecDataTableFrame tableFrame = new HecDataTableFrame(null);
		 tableFrame.setData(tsc);
		 tableFrame.setVisible(true);

		HecDataManager.closeAllFiles();  //  Only at the end of the program
	}
}

JAVA