📄 channel.java
字号:
package org.trinet.jasi;
import java.sql.Date;
import java.sql.Connection;
import java.util.*;
import java.io.*;
import org.trinet.jdbc.datatypes.*;
import org.trinet.util.gazetteer.LatLonZ;
import org.trinet.util.gazetteer.GeoidalUnits;
import org.trinet.util.DateTime;
import org.trinet.util.BenchMark;
/**
* Seed channel object. Contains a ChannelName member which includes
* descriptive information for the channel like location
* of the site (latlonz) and response info. <p>
*
* @See: org.trinet.jasi.ChannelName
*/
public abstract class Channel extends JasiObject
implements Cloneable, AuthChannelIdIF, java.io.Serializable, Channelable
{
/** Channel description identifier */
protected ChannelName channelId = new ChannelName();
/** Location of the sensor. Note that 'z' is in km with down negative. */
public LatLonZ latlonz = new LatLonZ();
/** Emplacement depth in kilometers. Zero unless this is a downhole sensor. */
public DataDouble depth = new DataDouble(0.0);
/** Distance of this channel from the last point for which calcDistance was called.
* Usually it the associated solution in km. Used for distance sorting, etc. Defaults to
* 9999.9 so channels with unknown distances show up at the END of a list. This is the true
* distance taking into account depth and elevation. */
public DataDouble dist = new DataDouble(9999.9);
/** Horizontal distance of this channel.*/
public DataDouble hdist = new DataDouble(9999.9);
/** Azimuth from the station/channel to the associated Solution. Degrees
clockwise from north.*/
public DataDouble azimuth = new DataDouble();
/** Nominal sample rate (samples/second) expected for this channel.
* The actual data rate of retreived time series may differ.*/
public DataDouble sampleRate = new DataDouble();
// Response response;
/** The instrument gain.<br>
Units are counts/cm/sec for velocity or counts/cm/sec^2 for acceleration.
*/
public ChannelGain gain = new ChannelGain();
/** ML correction. Static correction to be added to calculated ML. */
public DataDouble mlCorr = new DataDouble();
/** ME correction. Static correction to be added to calculated ME. */
public DataDouble meCorr = new DataDouble();
/** Mca correction. Static correction to be added to calculated Mca.
* This is not currently read from the database. */
public DataDouble mcaCorr = new DataDouble();
/** If true only currently active channels will be added to the list. */
static boolean getCurrent = true;
protected static boolean debug = false;
// -- Concrete FACTORY METHODS ---
/**
* Factory Method: This is how you instantiate a jasi object. You do
* NOT use a constructor. This is so that this "factory" method can create
* the type of object that is appropriate for your site's database.
* If no type is specifed it creates a Channel object of the DEFAULT type.<br>
* @See: JasiObject
*/
public static final Channel 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.<br>
* @See: JasiObject
*/
public static final Channel 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.<br>
* @See: JasiObject
*/
public static final Channel create(String suffix) {
return (Channel) JasiObject.newInstance("org.trinet.jasi.Channel", suffix);
}
// ////////////////////////////////////////////////////////////////////////////
/** Set this channel's name. The components of the channel name are copied
* to the ChannelName object.
* Returns Channel so you can construct with call like:
* Channel chan = Channel.create().setChannelName("CI", "COK", "EHZ");*/
public Channel setChannelName (ChannelName cname) {
channelId = (ChannelName) cname.clone();
return this;
}
/**
* Set these parts of the channel name. Unspecified parts are left null.
*/
public Channel setChannelName ( String net, String sta, String comp){
channelId = new ChannelName(net, sta, comp);
return this;
}
/**
* Set these parts of the channel name. Unspecified parts are left null.
*/
public Channel setChannelName ( String net,
String sta,
String comp,
String seedchan)
{
channelId = new ChannelName(net, sta, comp, seedchan);
return this;
}
/**
* Set these parts of the channel name. Unspecified parts are left null.
*/
public Channel setChannelName ( String net,
String sta,
String comp,
String auth,
String subsource)
{
channelId = new ChannelName(net, sta, comp, auth, subsource);
return this;
}
/**
* Set these parts of the channel name. Unspecified parts are left null.
*/
public Channel setChannelName ( String net,
String sta,
String comp,
String auth,
String subsource,
String channelsrc,
String seedchan,
String location)
{
channelId = new ChannelName(net, sta, comp, auth, subsource, channelsrc, seedchan, location);
return this;
}
/** Return the ChannelName object of this Channel */
public ChannelName getChannelName() {
//return this;
return channelId;
}
public AuthChannelIdIF getChannelId() {
//return this;
return channelId;
}
// Implement AuthChannelIdIF
/** Return ASCII representation of the channel name with the fields delimited
* by the given char. */
public String toDelimitedString(char delimiter) {
return channelId.toDelimitedString(delimiter);
}
/** Return ASCII representation of the channel name with the fields delimited
* by the given string. */
public String toDelimitedString(String delimiter) {
return channelId.toDelimitedString(delimiter);
}
/** Return ASCII representation of the channel name with the fields delimited
* by "." */
public String toDelimitedString() {
return channelId.toDelimitedString();
}
/** Return ASCII representation of the channel SEED name with the fields delimited
* by the given char. */
public String toDelimitedSeedString(char delimiter) {
return channelId.toDelimitedSeedString(delimiter);
}
/** Return ASCII representation of the channel SEED name with the fields delimited
* by the given string. */
public String toDelimitedSeedString(String delimiter) {
return channelId.toDelimitedSeedString(delimiter);
}
/** Return ASCII representation of the channel SEED name with the fields delimited
* by "." */
public String toDelimitedSeedString() {
return channelId.toDelimitedSeedString();
}
public String getSta() {
return channelId.getSta();
}
public String getNet() {
return channelId.getNet();
}
public String getSeedchan() {
return channelId.getSeedchan();
}
public String getLocation() {
return channelId.getLocation();
}
public String getChannel() {
return channelId.getChannel();
}
public String getChannelsrc() {
return channelId.getChannelsrc();
}
public String getAuth() {
return channelId.getAuth();
}
public String getSubsource() {
return channelId.getSubsource();
}
public void setSta(String sta) {
channelId.setSta(sta);
}
public void setNet(String net) {
channelId.setNet(net);
}
public void setLocation(String location) {
channelId.setLocation(location);
}
public void setChannel(String channel) {
channelId.setChannel(channel);
}
public void setSeedchan(String seedchan) {
channelId.setSeedchan(seedchan);
}
public void setChannelsrc(String channelsrc) {
channelId.setChannelsrc(channelsrc);
}
public void setAuth(String auth) {
channelId.setAuth(auth);
}
public void setSubsource(String subsource) {
channelId.setSubsource(subsource);
}
public double getSampleRate() {
return sampleRate.doubleValue();
}
public void setSampleRate (double rate) {
sampleRate.setValue(rate);
}
// End of AuthChannelIdIF
/**
* Return 'TRUE' if the channel is a vertical component (V or Z)
*/
public boolean isVertical() {
String channel = channelId.getChannel();
if (channel.length() >= 3) { // guard against short components
char comp = channel.charAt(2); //get 3rd character (starts with 0)
if (comp == 'V' || comp == 'Z') return true;
}
return false;
}
/** Return true if this channel is a low-gain component */
public boolean isLowGain() {
return getChannelName().getSeedchan().substring(1,2).equalsIgnoreCase("L");
}
/** Return true if this channel is a high-gain component */
public boolean isHighGain() {
return getChannelName().getSeedchan().substring(1,2).equalsIgnoreCase("H");
}
/** Return true if the channel is a broadband (SEED 'B__') */
public boolean isBroadBand() {
return getChannelName().getSeedchan().substring(1,1).equalsIgnoreCase("B");
}
/** Set flag that if true will cause only currently active channels to be
* added to the static channel list.*/
public static void setCurrentFlag (boolean tf) {
getCurrent = tf;
}
/** Returns the value of the flag that if true will cause only currently
* active channels to be added to the static channel list.*/
public static boolean getCurrentFlag () {
return getCurrent;
}
/** Calculate and set both epicentral (horizontal) distance and true (hypocentral)
* distance of this channel from the given location in km. Returns hypocentral
* distance. Also sets azimuth.
* Note: this is better than setDistance() or setHorizontalDistance() because
* it does both and insures they are consistent. If the channel's LatLonZ or
* the LatLonZ in the argument is null, both distances are set = 9999.9*/
static final double NULL_DIST = 9999.9;
public double calcDistance (LatLonZ loc) {
if (loc == null || loc.isNull() || !hasLatLonZ()) { // lat/lon unknown
setDistance(NULL_DIST); // so they'll be at END of a sorted list
setHorizontalDistance(NULL_DIST);
// leave azimuth null
} else {
setDistance(this.latlonz.distanceFrom(loc));
setHorizontalDistance(this.latlonz.horizontalDistanceFrom(loc));
setAzimuth(this.latlonz.azimuthTo(loc));
}
return getDistance();
}
/** Set hypocentral distance ONLY. NOTE: calcDistance(LatLonZ) is prefered because
* it sets both hypocentral and horizontal distance. */
public void setDistance(double distance) {
dist.setValue(distance);
}
/** Set horizontal distance ONLY. NOTE: calcDistance(LatLonZ) is prefered because
* it sets both hypocentral and horizontal distance. */
public void setHorizontalDistance(double distance) {
hdist.setValue(distance);
}
public double getDistance() {
return dist.doubleValue();
}
public double getHorizontalDistance() {
return hdist.doubleValue();
}
public void setAzimuth(double az) {
azimuth.setValue(az);
}
public double getAzimuth() {
if (azimuth == null || azimuth.isNull() || azimuth.doubleValue() == Double.NaN) return 0.0;
return azimuth.doubleValue();
}
/** Needed for Channelable interface. */
// Can't call it getChannel() because that's used to return channel string
public Channel getChannelObj() {
return this;
}
public void setChannelObj(Channel chan) {
this.copy(chan);
}
/** Return true if the channel has a vaild LatLonZ, false if not. */
public boolean hasLatLonZ () {
return !(this.latlonz == null || this.latlonz.isNull()) ;
}
/** Return the index of this channel in this collection of Channelable objects.
* Returns -1 if list is empty, it doesn't contain Channelable objects or this
* channel is not in the list. */
public int indexOf (Collection list) {
if (list == null || list.isEmpty()) return -1;
ArrayList alist = (ArrayList) list;
if (!(alist.get(0) instanceof Channelable)) return -1;
Channel channel;
for (int idx = 0; idx < list.size(); idx++) {
channel = ((Channelable) alist.get(idx)).getChannelObj();
if (this.equalsIgnoreCase(channel)) return idx;
}
return -1;
}
/**
* Make a "deep" copy.
*/
public Channel copy(Channel chan)
{
channelId = (ChannelName) chan.getChannelId().clone();
latlonz.copy( chan.latlonz );
depth = new DataDouble(chan.depth);
dist = new DataDouble(chan.dist);
azimuth = new DataDouble(chan.azimuth);
gain = new ChannelGain(chan.gain);
mlCorr = new DataDouble(chan.mlCorr);
meCorr = new DataDouble(chan.meCorr);
return this;
}
/**
* Return brief channel name with LatLonZ.
*/
public String toString(){
return channelId.toDelimitedString(' ') + " " + latlonz.toString() ;
}
/**
* Complete object dump. For debugging. Overides ChannelName.toDumpString()
* to include LatLonZ.
*/
public String toDumpString(){
String str =
" net: " + channelId.getNet()+
" sta: " + channelId.getSta() +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -