📄 waveformtn.java
字号:
}
catch (SQLException ex) {
System.err.println(ex);
ex.printStackTrace();
}
return root;
}
/**
* Return the waveform file root for a particular event id.
* Access to this path is tested
* to determine if files can be read locally.
*/
protected String getFileRoot(long eventId) {
String root = "";
// get the data directory root from the data base
String sql = "select wavefileRootByEvid(" + eventId + ") from dual";
try {
Statement sm = DataSource.getConnection().createStatement();
ResultSet rs = sm.executeQuery(sql);
rs.next();
root = rs.getString(1);
sm.close();
}
catch (SQLException ex) {
System.err.println(ex);
ex.printStackTrace();
}
return root;
}
/**
* Returns 'true' if this waveform's files are local,
* i.e. are on a file system where they can be opened either on the client
* machine or NFS mounted.
* Needs a DataSource open connection.
*/
public boolean fileIsLocal() {
// check existance
File file = new File(getPathFilename());
System.out.println ("file: "+file.toString());
return file.exists();
}
/** Returns true if this Waveform is accessible through some transport
* method. */
/* DEPRECATED
public boolean isAccessible () {
if (filesAreLocal()) return true;
// try remote reader
// NOTE: we assume the waveforms are reachable via FTP at the
// same IP address as the DataSource
String remoteHost = DataSource.getIPAddress(); // default data source;
RemoteFileReader remoteReader = new RemoteFileReader(remoteHost);
return remoteReader.isConnected();
}
*/
/**
* Load the time series data for this Waveform. This is done as a separate step
* because it is often more efficient to only load selected waveforms after
* you have examined or sorted the Waveform objects by their header info.<p>
*
* The waveform is collapsed into the minimum number of WFSegments possible. More
* then one WFSegment would only be necessary if there are time tears. The start-stop
* times of the original data packets is preserved in the packetSpans array.<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>
*
*/
// Should method be synchronized so only one class will try to load waveform at a time?
// public synchronized boolean loadTimeSeries() {
public boolean loadTimeSeries() {
return loadTimeSeries(getStart().doubleValue(), getEnd().doubleValue());
}
public boolean loadTimeSeries(double startTime, double endTime) {
// debug
// System.out.println("Loading: "+this.toString());
if (hasTimeSeries() && (getStart().doubleValue() == startTime) &&
(getEnd().doubleValue() == endTime) ) return true;
// Note that synchronizing the Method does NOT provide thread safty because
// other threads can modify the Waveform via other methods.
// synchronized (this) { // synchronize for thread safty
// only SEED is currently implemented
if (format.intValue() == SEED_FORMAT) {
// read data from Seed file
SeedReader.getData(this, startTime, endTime);
// came up empty
if (!hasTimeSeries()) return false;
// concatinate contiguous segments
collapse();
// set max, min, bias values
scanForAmps();
scanForBias();
// Notify any listeners that Waveform state has changed
// (changeListener logic is in jasiObject())
fireStateChanged();
return true; // success
}
// } // end of synch
return false;
}
/**
* Override Waveform.filesAreLocal() to always return false so dbase access of waveforms
* will be used.
*/
public boolean filesAreLocal()
{
return false;
}
/**
* Main for testing
* NOTE!!! to run main from within a package use:
*
* java org.trinet.jdbc.Waveform
*/
public static void main (String args[]) {
System.out.println ("Making connection...");
//DataSource ds = new TNDataSource("makalu");
//DataSource ds = new TNDataSource("k2");
DataSource ds = new TestDataSource("iron");
int evid = 701559;
// TEST 0 -- test getting wiggle for latest waveform
// int wfid = 82565122; // 100 sps
//int wfid = 13356047; // 10 sec/sample DAN.VHZ
//int wfid = 93588568; // 1983, 50 sps converted CUSP data
int wfid = 99403734; // 1981, 50 sps converted CUSP data
Waveform wfx = Waveform.create();
wfx = wfx.getByWaveformId(wfid);
System.err.println (wfx.toString());
System.err.println (wfx.toBlockString());
System.err.println ("Fetching waveform using DataSource: "+wfx.getChannelObj().toString());
// force filename
// wfx.setFilename("2046133");
// wfx.setPath("/wavearchive2/trig/1992/199204/");
// wfx.setFilename("701559");
// wfx.setPath("/home/awwalter/");
System.err.println (wfx.toString());
if (wfx.loadTimeSeries()) {
System.out.println ("Got waveform: nsegs = "+ wfx.getSegmentList().size() );
// System.out.println ("Expected samps = "+ wfx.sampleCount.toString() );
System.out.println ("Actual samps = "+ wfx.samplesInMemory() );
System.out.println ("max = "+ wfx.getMaxAmp());
System.out.println ("min = "+ wfx.getMinAmp());
System.out.println ("bias= "+ wfx.getBias());
} else {
System.out.println ("Waveform retreival failed.");
}
// test noise scan
wfx.scanForNoiseLevel();
// Test subsetting of waveform
if(wfx.getSegmentList().size() > 0)
{
WFSegment[] seglist = (WFSegment[])(wfx.getSegmentList().
toArray(new WFSegment[wfx.getSegmentList().size()]));
for (int i = 0; i < wfx.getSegmentList().size(); i++) {
WFSegment seg = seglist[i];
System.out.println ( seg.toString() );
}
}
TimeSpan ts = wfx.getTimeSpan();
double start = ts.getStart() + 10.0;
double end = ts.getEnd() - 10.0;
wfx.scanForNoiseLevel(start, end);
ArrayList segList = (ArrayList) wfx.getSubSegments(start, end);
System.out.println ("Trimmed waveform: nsegs = "+ segList.size() );
for (int i = 0; i < segList.size(); i++) {
WFSegment seg = (WFSegment) segList.get(i);
System.out.println ( seg.toString() );
}
// test wave client reader
WaveClient waveClient = null;
if (false) {
// cheating
String propFile = "/home/tpp/src/waveserver/rt/WaveClient.properties";
try {
// Make a WaveClient
System.out.println ("Creating WaveClient using: "+propFile);
waveClient = WaveClient.CreateWaveClient().ConfigureWaveClient(propFile); // property file name
System.out.println (waveClient.toString());
int nservers = waveClient.numberOfServers();
if (nservers <= 0) {
System.err.println("getDataFromWaveServer Error:"+
" no data servers specified in input file: " +
propFile);
System.exit(-1);
}
}
catch (Exception ex) {
System.err.println(ex.toString());
ex.printStackTrace();
}
finally {
// if (waveClient != null) waveClient.close();
}
// Get all time-series from a wave server
Waveform.setWaveSource (waveClient);
System.out.println ("***** Attempting to load time series from WaveServer *******");
wfx.unloadTimeSeries();
boolean status = wfx.loadTimeSeries();
System.out.println ("Status = "+status);
}
if (false) {
// TEST 1
WaveformTN wf = new WaveformTN();
wf = (WaveformTN)wf.getByWaveformId(wfid);
System.out.println ("filesAreLocal ="+ wf.filesAreLocal() );
System.err.println (" One by wfid...");
System.err.println (wf.toString());
System.err.println ("Got waveform: nsegs = "+ wf.segList.size() );
}
if (false) {
// TEST 2 -- test retreival by evid
System.err.println (" Many by evid...");
System.err.println ("Fetching waveforms pointer info...");
ArrayList wfarr = (ArrayList) Waveform.create().getBySolutionId(evid);
Waveform wfa[] = new Waveform[wfarr.size()];
wfarr.toArray(wfa);
// Waveform wfa[] = (Waveform[]) wfarr.toArray(new Waveform[0]);
System.err.println ("Waveform count = " + wfa.length);
for (int i = 0; i<wfa.length; i++)
{
System.err.println (wfa[i].toString());
}
}
}
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -