Sometimes one is interested in which records have changed in a DSS file from an earlier point in time. It may be a program "looking" at a DSS file in order to process data that another program has entered, or a modeling program wants to know if a dataset at a computation point has changed, requiring a recompute. This can be determined by using the "what changed" function in the HecDssCatalog class.

The whatChanged function will report back pathnames for all records that have changed since a start point based on either a last write time, or on a CRC (Cycle Redundancy Check) value for data within the record. The last write time basis is fast, but will return pathnames for datasets that have been written to, regardless if the actual data has changed (.e.g, zeros written over with zeros).

Using CRC values is slower, but will return pathnames for the datasets that have actually changed, not just written to. If the process to be performed subsequently were slow, such as transferring the data over a network, you would want to use the CRC option.
This method requires two calls: set a start point, then later calling get pathnames for changed records call. For example:

HecDssCatalog myCatalog;
myCatalog.whatChangedSetStart(…)
// Do computes or something
String pathnames[] = myCatalog.whatChanged();

The whatChangedSetStart function has two arguments; the first is a pathname string with wild characters to search for, or null for all records, and the second is a boolean set to true to indicate if CRC values should be calculated and used for each record with a pathname that matches the pathname with wild characters, or false to indicate that just a last write time should be used. Wild characters have been discussed previously. whatChangedSetStart returns the number of pathnames matching the pathnameWithWildChars, or a negative number for an error. The call is:

public int whatChangedSetStart(String pathnameWithWildChars, boolean useCRCforData);
JAVA

The call to obtain the list of pathnames for records that have changed since the setStart is:

  • public String[] whatChanged()

You can have several different HecDssCatalog objects for different types of datasets. For example, you may have one for flows and another for precipitation.

Example: What Changed Functions



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

//  An example of determing what data in a DSS file has changed
//
public class ExampleCatalog3 {

	public static void main (String args[])  {
	
		HecDssCatalog catalog = new HecDssCatalog();
		int status = catalog.setDSSFileName("C:/temp/Sample7.dss");
		if (status != 0) {
			System.out.println("Cannot access DSS file: C:/temp/Sample7.dss" );
			return;
		}
		//  public int whatChangedSetStart(String pathnameWithWildChars, boolean useCRCforData)
		//  pathnameWithWildChars = "/*/*/Flow/*/*/Study 1/".  CRC checks data changes, not last write
		catalog.whatChangedSetStart(null, true);
		
		//  Do stuff, computes, etc.
		HecTimeSeries ts = new HecTimeSeries();
		ts.setDSSFileName("C:/temp/Sample7.dss");
		TimeSeriesContainer tsc = new TimeSeriesContainer();
		tsc.setName("//SACRAMENTO/TEMP-MAX/01Jan1900/1Day/OBS/");
		HecTime start = new HecTime("20June1950", "0001");
		tsc.setStartTime(start);
		HecTime end = new HecTime("01Oct1970", "2400");
		tsc.setEndTime(end);
		status = ts.read(tsc, true);
		if (status != 0) return;
		//  Multiply by 2
		double vals[] = tsc.getValues();
		for (int i=0; i<vals.length; i++) {
			vals[i] *= 2.0;
		}
		tsc.setValues(vals);
		status = ts.write(tsc);
		ts.done();

		String[] paths = catalog.whatChanged();
		if (paths.length > 0) {
			//  Sort the pathnames to look nice
			String[] pathnames = catalog.sort();
			catalog.done();
			if (pathnames != null) {
				System.out.println(pathnames.length + " pathnames changed.  They are: " );
				for (int j=0; j<pathnames.length; j++) {
					System.out.println(pathnames[j]);
				}
			}
		}  

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

JAVA

Example: What Changed Functions – Different kinds of data


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

//  An example of determing different kinds of datasets that have changed
//
public class ExampleCatalog4 {

	public static void main (String args[])  {
	
		HecDssCatalog catalog1 = new HecDssCatalog();
		int status = catalog1.setDSSFileName("C:/temp/Sample7.dss");
		if (status != 0) {
			System.out.println("Cannot access DSS file: C:/temp/Sample7.dss" );
			return;
		}
	
		//  public int whatChangedSetStart(String pathnameWithWildChars, boolean useCRCforData)
		//  pathnameWithWildChars = "/*/*/Flow/*/*/Study 1/".  CRC checks data changes, not last write
		catalog1.whatChangedSetStart("/*/*/Temp*/*/*/*/", true);
		HecDssCatalog catalog2 = new HecDssCatalog();
		status = catalog2.setDSSFileName("C:/temp/Sample7.dss");
		if (status < 0) return;
		catalog2.whatChangedSetStart("/*/*/Precip*/*/*/*/", true);
		
		//  Do stuff, computes, etc.
		HecTimeSeries ts = new HecTimeSeries();
		ts.setDSSFileName("C:/temp/Sample7.dss");
		TimeSeriesContainer tsc = new TimeSeriesContainer();
		tsc.setName("//SACRAMENTO/TEMP-MAX/01Jan1900/1Day/OBS/");
		HecTime start = new HecTime("20June1950", "0001");
		tsc.setStartTime(start);
		HecTime end = new HecTime("01Oct1970", "2400");
		tsc.setEndTime(end);
		status = ts.read(tsc, true);
		if (status != 0) return;
		//  Multiply by 2
		double vals[] = tsc.getValues();
		for (int i=0; i<vals.length; i++) {
			vals[i] *= 2.0;
		}
		tsc.setValues(vals);
		status = ts.write(tsc);
		tsc = new TimeSeriesContainer();
		tsc.setName("//SACRAMENTO/PRECIP-INC/01Jan1900/1Day/OBS/");
		tsc.setStartTime(start);
		tsc.setEndTime(end);
		status = ts.read(tsc, true);
		if (status != 0) return;
		//  Multiply by 5
		vals = tsc.getValues();
		for (int i=0; i<vals.length; i++) {
			vals[i] *= 5.0;
		}
		tsc.setValues(vals);
		status = ts.write(tsc);
		ts.done();

		

 
String[] paths = catalog1.whatChanged();
		if (paths.length > 0) {
			//  Sort the pathnames to look nice
			String[] pathnames = catalog1.sort();
			catalog1.done();
			if (pathnames != null) {
				System.out.println(pathnames.length + " Temperature pathnames changed.  They are: " );
				for (int j=0; j<pathnames.length; j++) {
					System.out.println(pathnames[j]);
				}
			}
		}
		
		paths = catalog2.whatChanged();
		if (paths.length > 0) {
			//  Sort the pathnames to look nice
			String[] pathnames = catalog2.sort();
			catalog2.done();
			if (pathnames != null) {
				System.out.println(pathnames.length + " Precip pathnames changed.  They are: " );
				for (int j=0; j<pathnames.length; j++) {
					System.out.println(pathnames[j]);
				}
			}
		}

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

 

JAVA