📄 waveform.java
字号:
package org.trinet.jasi;
import java.lang.*;
import java.io.File;
import java.util.*;
import java.sql.Connection;
import org.trinet.jdbc.datatypes.*;
import org.trinet.util.*;
import org.trinet.util.WaveClient;
//import org.trinet.filters.GenericFilter;
/**
* Represents the waveform time series for one channel for a time window (TimeSpan).
* Because a time window may contain gaps or no data, the TimeSeries may contain
* from zero to 'n' WFSegments. Each WFSegment is a CONTIGOUS time series.<p>
*
* Fires ChangeEvents when the time-series is loaded so that time-series can be
* loaded asynchronously (in background thread) then notify a graphics object when
* loading is complete.<p>
*
* Note that a waveform may be "empty", that is contain no time series. This may be
* true before the loader thread has retreived the time-series. Check this
* condition using the boolean method hasTimeSeries(). <p>
*
* <b>Note on synchronization: </b> Waveforms can be loaded in a background thread.
* Therefore, care must be taken to make concrete methods that implement and extend
* this class THREAD SAFE. This is best done by synchronizing on the specific
* waveform instance ("this").
* For example:
<tt>
public class WaveformConcrete extends Waveform {
public void someMethod() {
synchronize (this) {
// modify the waveform here
}
}
}
<\tt>
* Extensions of this class are also responsible for knowing how to read in
* timeseries from various data sources.
* @see: loadTimeSeries()
* @see: loadTimeSeries(double startTime, double endTime)
* <p>
* The wave source is set using
* @see: setWaveSource(Object source)
*/
public abstract class Waveform extends JasiTimeSeries {
/** Time-series encoding format as defined in SEED v2.3, see SEED
* Ref. Man. pg. 106
*
* @See: org.trinet.jasi.SeedEncodingFormat() */
public DataLong encoding = new DataLong();
/** "C" = continuous, "T" = triggered. */
public DataString dataMode = new DataString();
/** Optional unique ID number of a waveform. May not exist in all systems.
* For NCDN schema data this would be the 'wfid'. */
public DataLong id = new DataLong();
/** Optional unique ID external number of a waveform. May not exist in all
systems. */
public DataString externalId = new DataString();
/** If the waveform is associated with a particular event in the underlying
data source, this is the unique ID of that event. */
public DataString savingEvent = new DataString(); // event ID for which data was saved
// private, implimentation specific data members
/** The maximum amplitude sample. */
Sample maxSample;
/** The mminimum amplitude sample. */
Sample minSample;
/** Units of the amplitude dimension.
* @See: Units */
int ampUnits = Units.UNKNOWN;
/** The value of the bias (DC offset).*/
protected float biasVal = 0.0f;
/** Host where waveform file resides. */
protected String host;
/** Directory path to the waveform file. */
protected String path;
/** Filename of the waveform file. */
protected String filename;
/** Byte offset to data in file */
protected int fileOffset;
/** Number of bytes of data in the file for this waveform. */
protected int byteCount;
/* Enumerate time-series load source options */
public static final int LoadFromDataSource = 0;
public static final int LoadFromWaveServer = 1;
/** Default source of time-series data. These are static so ALL waveforms must
* be comming from the same data source. */
static int waveDataSourceType = LoadFromDataSource;
/* This will be either a DataSource (default) or a WaveClient */
// The following blows up if default data source is not available
// static Object waveDataSource = new DataSource();
static Object waveDataSource;
/** The travel-time model used to calculate the energy window. */
//TravelTime ttModel = new TravelTime();
TravelTime ttModel = TravelTime.getInstance();
// ////////////////////////////////////////////////////////////////////////////
/**
* Instantiate an object of this type. You do
* NOT use a constructor. This "factory" method creates various
* concrete implementations. Creates a Solution of the DEFAULT type.
* @See: JasiObject
*/
public static final Waveform create() {
return create(DEFAULT);
}
/**
* Instantiate an object of this type. You do
* NOT use a constructor. This "factory" method creates various
* concrete implementations. The argument is an integer implementation type.
* @See: JasiObject
*/
public static final Waveform create(int schemaType) {
return create(JasiFactory.suffix[schemaType]);
}
/**
* Instantiate an object of this type. You do
* NOT use a constructor. This "factory" method creates various
* concrete implementations. The argument is as 2-char implementation suffix.
* @See: JasiObject
*/
public static final Waveform create(String suffix) {
return (Waveform) JasiObject.newInstance("org.trinet.jasi.Waveform", suffix);
}
// ////////////////////////////////////////////////////////////////////////////
/** Do "deep" copy of the header, not the data, portion of the Waveform. */
public void copyHeader(Waveform wf) {
synchronized (wf) { // make sure another thread doesn't change it under us
setChannelObj((Channel)wf.getChannelObj().clone());
//setChannelObj(Channel.create().setChannelObj(wf.getChannelObj()));
format = new DataLong(wf.format);
encoding = new DataLong(wf.encoding);
dataMode = new DataString(wf.dataMode);
setSampleRate(wf.getSampleRate());
id = new DataLong(wf.id);
externalId = new DataString(wf.externalId);
// 'primative' arg passed by value :. not passed by ref
setStart(wf.getStart().doubleValue());
setEnd(wf.getEnd().doubleValue());
//timeStartActual = new DataDouble(wf.timeStartActual);
//timeEndActual = new DataDouble(wf.timeEndActual);
savingEvent = new DataString(wf.savingEvent);
if (wf.host != null) host = new String(wf.host);
if (wf.path != null) path = new String(wf.path);
if (wf.filename != null) filename = new String(wf.filename);
fileOffset = wf.fileOffset ;
byteCount = wf.byteCount;
waveDataSourceType = wf.waveDataSourceType;
// Note: this copies the reference to this Object
waveDataSource = wf.waveDataSource;
} // end of synch
} // end of copyHeader
/** Do "deep" copy of the WFSegments in the Waveform. */
public void copyTimeSeries(Waveform wf) {
if (wf.hasTimeSeries()) {
synchronized (wf) {
WFSegment seg[] = wf.getArray();
biasVal = getBias();
if (wf.getMaxSample() != null)
maxSample = wf.getMaxSample().copy();
if (wf.getMinSample() != null)
minSample = wf.getMinSample().copy();
for (int i=0; i < seg.length; i++) {
WFSegment wfs = new WFSegment();
wfs.copy(seg[i]);
segList.add(wfs);
}
} // end of synch
}
}
//** Return a "deep" copy of the passed waveform. */
public static Waveform copy (Waveform wf) {
Waveform newWf = Waveform.create();
newWf.copyHeader(wf);
newWf.copyTimeSeries(wf);
return newWf;
} // end of copy()
/** Set the source of the time-series data */
public static boolean setWaveSource (Object source) {
if (source instanceof DataSource) {
// debug
System.out.println ("Wavesource set to dbase.");
waveDataSource = source;
waveDataSourceType = LoadFromDataSource;
return true;
} else if (source instanceof WaveClient) {
System.out.println ("Wavesource set to waveserver.");
waveDataSource = source;
waveDataSourceType = LoadFromWaveServer;
return true;
}
System.out.println ("Waveform: bad waveform data source.");
return false;
}
public static Object getWaveSource () {
return waveDataSource;
}
/** Return a string describing the data source. It its a WaveClient is
* returned. If its a dbase a string of the form "dbase@host" is returned.*/
public static String getWaveSourceName () {
if (getWaveSourceType() == LoadFromDataSource) {
return ((DataSource)waveDataSource).getDbaseName()+
"@"+((DataSource)waveDataSource).getHostName();
} else if (getWaveSourceType() == LoadFromWaveServer) {
return "WaveServer";
} else {
return "";
}
}
public static int getWaveSourceType () {
return waveDataSourceType;
}
/**
* Return string with path/filename for this waveform
*/
public String getPathFilename() {
// return path+"/"+filename;
return path+filename;
}
/**
* Set the Path string. Expects a trailing "/" in UNIX or
* "\" in WINTEL
*/
public void setPath (String path) {
this.path = path;
}
/**
* Set the filename string.
*/
public void setFilename (String filename) {
this.filename = filename;
}
/**
*
*/
public int getFileOffset() {
return fileOffset;
}
/**
*
*/
public void setFileOffset(int IN_iFileOffset) {
fileOffset = IN_iFileOffset;
}
/**
*
*/
public int getByteCount() {
return byteCount;
}
/**
* Returns the TimeSpan covered by the time-series. It may contain holes.
*/
public TimeSpan getTimeSpan()
{
return new TimeSpan ( timeStart.doubleValue(), timeEnd.doubleValue());
}
/**
* Get one waveform from the DataSource by Waveform record ID #
*/
public abstract Waveform getByWaveformId (long wfid);
/**
* Get an array of waveforms from the DataSource by solution ID #
*/
public abstract Collection getBySolutionId (long id);
/**
* Get an array of waveforms from the DataSource by solution ID #
*/
public abstract Collection getBySolution (Solution sol) ;
/**
* Returns 'true' if generic waveform path as returned by the dbase are local
* i.e. are on a file system where they can be opened either on the client
* machine or NFS mounted.
* Gets generic waveform file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -