As an option DSS-7 can store time series data with a granularity of one second (the default is a granularity of one minute). This means is that the smallest time interval for regular and irregular interval data is one second, and that irregular-interval data can have a granularity of one second.

 
Inside the DSS library a date/time is stored as an integer, and time granularity determines the precision of that number.
For regular interval data, all E parts that contain "Seconds" automatically use a second granularity.

Time arrays retrieved from such records will have a second granularity also. To store other data (including irregular interval), with second granularity set the TimeSeriesContainer timeGranularitySeconds = 1 prior to setting times in the container.


As a note, with second granularity, regular ints can overflow for seconds from a date of 01Jan1900. To mitigate this, a Julian "base date" is employed (TimeSeriesContainer.julianBaseDate). For second granularity, the base date is usually the Julian date of the D (date) part of the first pathname in the data set, and all data times are times from that base date.

With minute granularity data, the base date is usually zero, so often computations can usually get away ignoring it, but the conventions say that is to be used for date computations. For second granularity data, the base date is usually not zero, and is included in the calculations for the returned time array.





Possible Granularities

granularity

TimeSeriesContainer

timeGranularitySeconds

1 second

1

1 minute

 60

1 hour

 3600

1 day

 24*6300




Example: Regular-interval time series data with second granularity


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 
//  regular-interval time series data with second granularity 
//
public class ExampleTimeSeries4 {

	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<values.length; i++) {
			values[i] = (double)i;
		}
		tsc.setValues(values);
		HecTime hecTime = new HecTime("20Jan2011", "1200");
		tsc.setStartTime(hecTime);
		//  The E part of "5Seconds" identifies as having second granularity
		tsc.setName("/Basin/Location/Flow//5Seconds/Java Second Granularity/");
		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();
		//  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/20Jan2011/5Seconds/Java Second Granularity/");
		HecTimeSeries dssTimeSeriesRead = new HecTimeSeries();
		dssTimeSeriesRead.setDSSFileName("C:/temp/Example7.dss");		
		status = dssTimeSeriesRead.read(tscRead, true);
		dssTimeSeriesRead.done();		
		if (status != 0) return;
		//  The times in the time array will automatically use second granularity
		//  Also tsc.timeGranularitySeconds == 1
		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();  //  Only at the end of the program
	}
}

JAVA


Example: Irregular-interval time series data with second granularity

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 ExampleTimeSeries5 {

	public static void main (String args[])  {

		try {
			javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception ignore) {}
		
		//  Write an 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(HecTime.SECOND_GRANULARITY);
		hecTime.set("20Jan2010", "1200");
		for (int i=0; i<200; i++) {
			values[i] = (double)i;
			//  Make it irregular by adding 10 seconds for even, subtracting for odd
			if (i % 2 == 0) {
				hecTime.addSeconds(20 + 10);
			}
			else {
				hecTime.addSeconds(20 - 10);
			}
			times.setElementAt(new HecTime(hecTime), i);
		}
		TimeSeriesContainer tsc = new TimeSeriesContainer();
		tsc.set(values, times);
		tsc.setName("/Basin/Location/Flow//Ir-Month/Second Granularity/");		
		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/Second Granularity/");
		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