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

📄 channellist.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    /** Returns the default ChannelList file name. */
    public static String getAsciiFilename() {

  if (asciiFilename == null) setAsciiFilename(getFullDefaultAsciiFilename());

  return asciiFilename;

    }
    public static void setAsciiFilename(String filename) {
  asciiFilename = filename;
    }

    /** Returns the default file path name. */
    public static String getDefaultPath() {

  if(System.getProperty("JIGGLE_USER_HOMEDIR") != null)
          return(System.getProperty("JIGGLE_USER_HOMEDIR"));
        else
          return(System.getProperty("user.home","."));
    }
    /** Returns the default ChannelList file name. */
    public static String getDefaultCacheFilename() {

      return "channelList.cache";

    }
    /** Returns the default ChannelList path and file name. */
    public static String getFullDefaultCacheFilename() {

      return getDefaultPath() + FileSep + "channelList.cache";

    }

    /** Returns the default ChannelList file name. */
    public static String getFullDefaultAsciiFilename() {

      return getDefaultPath() + FileSep + "channelList.list";

    }

    /** Returns the default ChannelList file name. */
    public static String getFullDefaultBinaryFilename() {

      return getDefaultPath() + FileSep + "channelList.bin";

    }

/**
 * Return Collection of currently active Channels from the default
 * DataSource Connection..
 */
    public static ChannelList readCurrentList() {
  // use NOW
    return Channel.create().readList();
    }
/**
 * Return Collection of Channels that were active on the given date.
 * Uses the default DataSource Connection.
 */
    public static ChannelList readList(java.sql.Date date) {
  return Channel.create().readList(date);
    }
/**
 * Return an array of Channels that were active on the given date.
 * Uses the default DataSource Connection.
 */
    /* NOTE on timing: reading in 2215 rows takes about 20 sec. on an USparc
     * over the network :. the rate is about 100 rows/sec.
     * When looking up each channel in a seperate query you get about 9 chans/sec
     * :.  the crossover point is about 180 channels. I.e. its more efficient to do
     * individual lookups if its a one time deal and there are less then 180 chans.
     */

    public static ChannelList readList(Connection conn, java.sql.Date date) {
  return Channel.create().readList(conn, date);
//	return Channel.create().readList(Channel.getDateWhereClause(date);

    }

     /** Return count of all channels in data source. */
    public static int getCurrentCount () {
      return Channel.create().getCurrentCount();
    }

    /** Return count of all channels in data source. */
    public static int getCount (java.sql.Date date) {

       return Channel.create().getCount(date);

    }
/**
 * Return Collection of ALL Channels that were in the DataSource. There may be
 * multiple entries for a channel that represent changes through time.
 * Uses the default DataSource Connection.
 */
    public static ChannelList readAllList()
    {
  return readAllList (DataSource.getConnection());
    }

    public static ChannelList readAllList(Connection conn)
    {
  return Channel.create().readList();
    }

    /** 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 static ChannelList getByComponent(String[] compList) {
        return Channel.create().getByComponent(compList);
    }

    /** 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 static ChannelList getByComponent(String[] compList,  java.sql.Date date) {

        return Channel.create().getByComponent(compList, date);
    }

    /**
     * Find the given Channel in the static channel list. If no entry is
     * found, this method returns the channel name that was passed in the arg as
     * a ChannelNamel.  */
    public Channel findExactInList (Channel chan) {

  Channel ch[] = getArray();

// No efficient way to do this unless we put Channel list in hash table
  for (int i = 0; i < ch.length; i++)
  {
            ChannelName chanName = chan.getChannelName();
      if (chanName.equalsIgnoreCase(ch[i].getChannelName())) {
    return ch[i];		// substitute
      }
  }
  return (Channel) chan;
    }

    /**
     * Find the given Channel in this channel list. If no entry is
     * found, this method returns the channel that was passed in the arg as
     * a Channel.  */
    public Channel lookUp (Channel chan) {
        return findSimilarInList(chan);
    }
    /**
     * Find the given Channel in this channel list. If no entry is
     * found, this method returns the channel name that was passed in the arg as
     * a Channel.  */
    public Channel findSimilarInList (Channel chan) {

  Channel ch[] = getArray();

// No efficient way to do this unless we put Channel list in hash table
  for (int i = 0; i < ch.length; i++)
  {
            ChannelName chanName = chan.getChannelName();
      if (chanName.sameAs(ch[i].getChannelName())) {
    return ch[i];		// substitute
      }
  }
  return (Channel) chan;
    }

    /** Try reading the local cached channel list, if that fails
    read the data source and create a cache list. */
    public static ChannelList smartLoad() {

      ChannelList chanList = ChannelList.readFromCache();

        // cache read failed, read from dbase and write to cache for future use
        if (chanList.isEmpty()) {
           chanList = ChannelList.readCurrentList();
           chanList.writeToCache();
        }

     return chanList;

    }

public String toString() {

  String str="";

  Channel[] ch = getArray();

  if (ch.length == 0) {
      str = ("No channels found.");
  } else {
      for (int i = 0; i < ch.length; i++)
      {
    str += ch[i].toString() + "\n";
      }
  }
  return str;
    }

    public String toDumpString() {

  String str="";

  Channel[] ch = getArray();

  if (ch.length == 0) {
      str = ("No channels found.");
  } else {
      for (int i = 0; i < ch.length; i++)
      {
    str += ch[i].toDumpString() + "\n";
      }
  }
  return str;
    }
/** Dump the Channel List directly to standard output. */
    public void dump() {
  Channel[] ch = getArray();

  if (ch.length == 0) {
      System.out.println("No channels found.");
  } else {
      for (int i = 0; i < ch.length; i++)
      {
    System.out.println(ch[i].toDumpString());
      }
  }
    }

// Inner class to perform Comparator methods for sorting by distance from epicenter

class DistanceSorter implements Comparator {

    public int compare (Object o1, Object o2) {

  Channel c1 = (Channel) o1;
  Channel c2 = (Channel) o2;

  double diff = c1.dist.doubleValue() - c2.dist.doubleValue();
        if (diff < 0.0) return -1;
        if (diff > 0.0) return  1;
  return 0;

    }

} // end of DistanceSorter inner class

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

        System.out.println ("Making connection... ");

        DataSource db = new TestDataSource();

        System.out.println (db.toString());

/*
  // 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 = new Channel("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 = new Channel("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);
      }
  }
*/
  String complist[] = {"HH_", "HL_", "EH_", "BH_"};

         ChannelList list = Channel.create().getByComponent(complist);
    // test serialization

    System.out.println ("Reading in current channel info ...");
    BenchMark bm  = new BenchMark();
    bm.print("Channels loaded = "+list.size());
    bm.reset();

    list.calcDistancesFrom(new LatLonZ(33.2, -116.5, 0.0));
    list.getMaximumAzimuthalGap();



//    boolean status = list.writeAsciiFile("channelList.test");
    boolean status = list.writeAsciiFile();

    bm.print( "Write ascii = "+status);
    bm.reset();

    ChannelList newList = new ChannelList();
    status = newList.readAsciiFile(ChannelList.getAsciiFilename());

    bm.print("Read ascii = "+status+ " size = "+newList.size());
    bm.reset();

    System.out.println ( "Write cache = " + list.writeToCache() );
    bm.print ("Write cache = "+list.size());
    bm.reset();

    list = new ChannelList();
//    System.out.println ("nuked it, list length = "+list.size());

    list = ChannelList.readFromCache();
    bm.print ( "Read cache = "+ list.size());
    bm.reset();

    System.out.println ( "Write binary = " + list.writeBinaryFile() );
    bm.print ("Write binary = "+list.size());
    bm.reset();

/// test cache
/*
    System.out.println ("Reading in current channel info from cache...");
    //ChannelList list2 = ChannelList.readFromCache();
    ChannelList list2 = ChannelList.smartLoad();

    System.out.println ( "Read cache, list length = "+
          list2.size());

//    System.out.println (list2.toString());
    System.out.println ( "Sort test...");

      list2.distanceSort(new LatLonZ(33., -117., 0.1));
      // dump list
  Channel cha[] = list2.getArray();
  String str="";

     int end = Math.min(cha.length, 30);
  if (cha.length == 0) {
      str = ("No channels in list.");
  } else {
      for (int i = 0; i < end; i++)
      {
    System.out.println (cha[i].toDumpString()+ " dist= "+cha[i].dist);
      }
  }
*/

 }  // end of Main



}

⌨️ 快捷键说明

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