⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channel.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      " channel: " + channelId.getChannel() +
      " seedchan: " + channelId.getSeedchan() +
      " location: " + channelId.getLocation()+
      " channelsrc: " + channelId.getChannelsrc() +
      " LatLonZ= "+ latlonz.toString() +
      " gain= "+ gain.doubleValue() +
      " mlCorr= "+mlCorr+
      " meCorr= "+meCorr;
  return str;
    }
    /** Return a string with all the members of a Channel object, delimited
    * by the given string. The string must be a single character if you
    * will read it back with parseCompleteString(). It also, should not be
    * a character that would appear in any of the members (letters and numbers). */
    public String toCompleteString(String delim) {
       return  toCompleteString (this, delim);
    }

    /** Return a string with all the members of a Channel object, delimited
    * by the given string. The string must be a single character if you
    * will read it back with parseCompleteString(). It also, should not be
    * a character that would appear in any of the members (letters and numbers). */
    public static String toCompleteString(Channel chan, String delim) {
      return chan.channelId.toCompleteString(delim) +
      delim + chan.latlonz.toString(delim) +
      delim + chan.gain.doubleValue() +
      delim + chan.gain.getUnitsString() +
      delim + chan.mlCorr.doubleValue() +
      delim + chan.meCorr.toString() ;
         //.doubleValue();
    }

    public boolean binaryWrite (DataOutputStream out) {
       return binaryWrite(this, out);
    }
    public boolean binaryWrite (Channel chan, DataOutputStream out) {

      boolean status = true;
      try {
       out.writeUTF(chan.getNet());
       out.writeUTF(chan.getSta());
       out.writeUTF(chan.getChannel());
       out.writeUTF(chan.getSeedchan());
       out.writeUTF(chan.getChannelsrc());
       out.writeUTF(chan.getLocation());

       out.writeDouble(chan.latlonz.getLat());
       out.writeDouble(chan.latlonz.getLon());
       out.writeDouble(chan.latlonz.getZ());

       out.writeDouble(chan.gain.doubleValue());
       out.writeInt(chan.gain.getUnits());
       out.writeDouble(chan.mlCorr.doubleValue());
       out.writeDouble(chan.meCorr.doubleValue());
      } catch (IOException ex) {
            ex.printStackTrace();
            status = false ;
      }
      return status;
    }

    public static Channel binaryRead (DataInputStream in) {

       Channel chan = Channel.create();

       try {

       chan.setNet(in.readUTF());
       chan.setSta(in.readUTF());
       chan.setChannel(in.readUTF());
       chan.setSeedchan(in.readUTF());
       chan.setChannelsrc(in.readUTF());
       chan.setLocation(in.readUTF());

       chan.latlonz.set(in.readDouble(), in.readDouble(), in.readDouble());

       chan.gain.gain.setValue(in.readDouble());
       chan.gain.setUnits(in.readInt());

       chan.mlCorr.setValue(in.readDouble());
       chan.meCorr.setValue(in.readDouble());
      } catch (IOException ex) {
            ex.printStackTrace();
      }

       return chan;

    }

    /** Parse a string for the format created by toCompleteString(). */
    public static Channel parseCompleteString (String str, String delim) {

       StringTokenizer strTok = new StringTokenizer(str, delim);

       Channel chan = Channel.create();

       try {
      chan.channelId = ChannelName.parseCompleteString(strTok);
      chan.latlonz = LatLonZ.parse(strTok);
         chan.gain.gain.parseValue(strTok);
         chan.gain.setUnits(strTok.nextToken());
         chan.mlCorr.parseValue(strTok);
         chan.meCorr.parseValue(strTok);

       } catch (NoSuchElementException ex) {}

       return chan;
    }

// /////////////////////////////////////////////////////////////////////////////

    public Object clone() {
        Channel chan = null;
        try {
            chan = (Channel) super.clone();
        }
        catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        chan.channelId = (ChannelName) channelId.clone();
  chan.latlonz = (LatLonZ) latlonz.clone();
  chan.depth   = (DataDouble) depth.clone();
  chan.dist    = (DataDouble) dist.clone();
  chan.azimuth = (DataDouble) azimuth.clone();
  chan.gain    = (ChannelGain) gain.clone();
  chan.mlCorr  = (DataDouble) mlCorr.clone();
  chan.meCorr  = (DataDouble) meCorr.clone();
        return chan;
    }

    /**
     * Case sensitive compare. Returns true if sta, net and seedchannel are
     * equal. Does not check the other fields.  The "extra" fields like
     * 'channel' and 'location' are populated in some data sources and not
     * others.
     */
    public boolean equals(Object x) {
        if (this == x) return true;
  else if ( x == null || ! (x instanceof Channel)) return false;
        Channel chan = (Channel) x;
  return(this.channelId.equals(chan.getChannelId()));
    }

    /**
     * Case insensitive compare. Returns true if sta, net and channel are
     * equal. Does not check the other fields.  Made necessary because not all
     * data sources populate all the fields.  Force a trim to remove trailing
     * blanks just in case the reader didn't.  ALSO returns true if sta & net
     * match and channel equals either the 'channel' OR <it> seedchan </it>
     * value. Does NOT check the value of 'location'. <p>
     * This includes a horrible kludge to get around the problem of renamed analog
     * channels. Considers "EHZ" == "VHZ"*/

    public boolean sameAs(Object x) {
  if ( !(x instanceof Channel) ) return false;
  Channel ch = (Channel) x;
  return ch.getChannelName().sameAs(channelId);
    }

    /** Returns true if the channels are from the same station. */
    public boolean sameStationAs(Object x) {
  if ( !(x instanceof Channel) ) return false;
  Channel ch = (Channel) x;
  return ch.getChannelName().sameStationAs(channelId);
    }

    /**
     * Case insensitive compare. Returns true if sta, net, and  channel or
     * 'seedchan' attributes are equal. <p>
     * ALSO returns true if sta & net match and  channel equals either the
     * 'channel' OR <it> seedchan </it> value. Does NOT check the value of 'location'. */
    public boolean equalsIgnoreCase(Object x) {
        if (this == x) return true;
  else if ( x == null || ! (x instanceof Channel)) return false;
        Channel chan = (Channel) x;
  return(this.channelId.equalsIgnoreCase(chan.getChannelId()));
    }
/*    public boolean equalsIgnoreCase(Object x) {
  if ( !(x instanceof Channel) ) return false;
  Channel ch = (Channel) x;
  return ch.getChannelName().equalsIgnoreCase(channelId);
    }
*/
/**
 * This uses just the essentials as in equals().
 */
    public int hashCode() {
        return channelId.hashCode();
    }
    protected void setHashValue() {
        channelId.setHashValue();
    }

/** Returns the result of comparing the strings generated by invoking toString() for this instance and the input object.
* Throws ClassCastException if input object is not an instanceof Channel.
* A return of 0 == value equals, <0 == value less than, >0 == value greater than, the string value of the input argument.
*/
    public int compareTo(Object x) {
  if (x == null ||  x.getClass() != getClass() )
     throw new ClassCastException("compareTo(object) argument must be a Channel class type: "
                                + x.getClass().getName());
  return channelId.toString().compareTo( ((Channel) x).getChannelId().toString());
    }
    /**
     * Look up the given Channel in the DataSource dbase and return a fully
     * populated Channel object. This is how you look up LatLonZ and response
     * info for a single channel. Note this finds the LATEST entry if more then
     * one entry is in the dbase (largest 'ondate'). But, it does NOT require that
     * the channel be "active". If no entry is found, this
     * method return the channel name that was passed in the arg as a Channel.
     */
    public static Channel lookUp (Channel chan) {
       return create().lookUpChannel(chan);
    }
// /////////////////////////////////////////////////////////////////////////////
// Abstract methods

    /**
     * Look up the given Channel in the DataSource dbase and return a fully
     * populated Channel object. This is how you look up LatLonZ and response
     * info for a single channel. Note this finds the LATEST entry if more then
     * one entry is in the dbase (largest 'ondate'). But, it does NOT require that
     * the channel be "active". If no entry is found, this
     * method return the channel name that was passed in the arg as a Channel.
     */
    public abstract Channel lookUpChannel (Channel chan) ;
/**
 * Return exhaustive Collection of Channels from the default DataSource.
 */
    public abstract ChannelList readList();
/**
 * Return Collection of Channels that were active on the given date.
 * Uses the default DataSource Connection.
 */
    public abstract ChannelList readList(java.sql.Date date);
/**
 * Return Collection of Channels that were active on the given date.
 * Uses the given DataSource Connection.
 */
    public abstract ChannelList readList(Connection conn, java.sql.Date date);
    /** Return a list of channels that were active on the given date and
    *  that match the list of component types given in
    * the array of strings. The comp is compared to the SEEDCHAN field in the NCDC
    * schema.<p>
    *
    * SQL wildcards are allowed as follows:<br>
    * "%" match any number of characters<br>
    * "_" match one character.<p>
    *
    * For example "H%" would match HHZ, HHN, HHE, HLZ, HLN & HLE. "H_" wouldn't
    * match any of these but "H__" would match them all. "_L_" would match
    * all components with "L" in the middle of three charcters (low gains).
    * The ANSI SQL wildcards [] and ^ are not supported by Oracle.*/
    public abstract ChannelList getByComponent(String[] compList,  java.sql.Date date) ;

    /** Return a list of currently acive channels that match the list of
     *  component types given in
    * the array of strings. The comp is compared to the SEEDCHAN field in the NCDC
    * schema.<p>
    *
    * SQL wildcards are allowed as follows:<br>
    * "%" match any number of characters<br>
    * "_" match one character.<p>
    *
    * For example "H%" would match HHZ, HHN, HHE, HLZ, HLN & HLE. "H_" wouldn't
    * match any of these but "H__" would match them all. "_L_" would match
    * all components with "L" in the middle of three charcters (low gains).
    * The ANSI SQL wildcards [] and ^ are not supported by Oracle.*/
    public abstract ChannelList getByComponent(String[] compList);

     /** Return count of all active channels in data source. */
    public abstract int getCurrentCount () ;

    /** Return count of all channels in data source that were active on this date. */
    public abstract int getCount (java.sql.Date date) ;

// ///////////////////////////////////////////////////////////////////////
/**
 * Main for testing:
 */
    public static void main (String args[]){

        System.out.println ("Making connection... ");
  DataSource dbase = new TestDataSource();
  System.out.println (dbase.toString());

    // look up one channel by name

//     System.out.println ("Current channel count = "+getCurrentCount());

  Channel cn = Channel.create().setChannelName("CI", "ALP", "BHE", "BHE");

  if (cn == null) {
      System.out.println ("cn is null.");
      System.exit(0);
  }

  System.out.println ("lookUp :"+cn.toDumpString());

  BenchMark bm = new BenchMark();

  Channel ch = cn.lookUp(cn);

  System.out.println ("found :"+ch.toDumpString());
  bm.print();

     System.out.println ("HypoFormat: /"+HypoFormat.toH2StationString(ch)+"/");
     String str = ch.toCompleteString(" ");
     System.out.println ("CompleteFmt: /"+str+"/");

     Channel newChan = Channel.parseCompleteString(str, " ");
     System.out.println ("CompletePrs: /"+newChan.toCompleteString(" ")+"/");


/*
//
  // NOTE: this demonstrates making a static Channel list.
        System.out.println ("Reading CURRENT channels...");
  bm.reset();
  //	Channel.setList (Channel.getAllList());
  Channel.setList (Channel.getCurrentList());

  //        System.out.println ("Reading channels with net=CI...");
  //	ArrayList chanList =
  //	    (ArrayList) Channel.readListWhere("Where net = 'CI'");

  System.out.println ("Found "+Channel.chanList.size()+" active channels.");
  bm.print();

  //
  Channel cn2 = Channel.create().setChannelName("NC", "PTQ", "VHZ", "EHZ");
  System.out.println ("Find "+cn2.toDumpString()+ " in list...");

  Channel found = Channel.findExactInList(cn2);

  if (found == cn2) {
      System.out.println ("No exact match found.");
  } else {
      System.out.println ("Found exact: " + found.toString());
  }

  found = Channel.findSimilarInList(cn2);
  if (found == cn2) {
      System.out.println ("No similar match found.");
  } else {
      System.out.println ("Found similar: " + found.toString());
  }

  //
  cn2 = Channel.create.setChannelName("CI", "HOD", "VHZ", "EHZ");
  System.out.println ("Find "+cn2.toDumpString()+ " in list...");

  found = Channel.findExactInList(cn2);

  if (found == cn2) {
      System.out.println ("No exact match found.");
  } else {
      System.out.println ("Found exact: " + found.toString());
  }

  found = Channel.findSimilarInList(cn2);
  if (found == cn2) {
      System.out.println ("No similar match found.");
  } else {
      System.out.println ("Found similar: " + found.toString());
  }

  // Test sorting

  Channel.distanceSort(new LatLonZ (34.35, -118.86, 8.0));

  // dump list
  Channel[] cha = getArray();
  String str="";

  int len = cha.length;
  //	int len = 100;

  if (cha.length == 0) {
      str = ("No channels in list.");
  } else {
      for (int i = 0; i < len; i++)
      {
    System.out.println (cha[i].toDumpString()+ " dist= "+cha[i].dist);
      }
  }


    // test serialization
    System.out.println ("Reading in current channel info ...");
    //Channel.setList (Channel.getCurrentList());
    Channel.setList (Channel.readListWhere(" Channel_Data.net = 'AZ'"));

    System.out.println ( "Write cache = " + Channel.writeCacheList() );
    System.out.println ("list length = "+Channel.listSize());
    System.out.println (Channel.currentListToString());

    Channel.chanList = null;
     System.out.println ("nuked it, list length = "+Channel.listSize());

    System.out.println ( "Read cache = " + Channel.readCacheList() );
    System.out.println ("list length = "+Channel.listSize());

    System.out.println (Channel.currentListToString());

    */

 }  // end of Main

}   // end of Channel class


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -