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

📄 locationenginehypoinverse.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

    // reset all solution dependent fields
    sol.clearLocationAttributes();

    // restore the event type
    sol.eventType = savedEventType;

    // read new solution dependent fields
    HypoFormat.parseArcSummary(sol, header);

    // set all the fields that HypoFormat doesn't have
    sol.authority.setValue(EnvironmentInfo.getNetworkCode());
    sol.source.setValue(EnvironmentInfo.getApplicationName());
    sol.method.setValue(locationMethod);
    sol.type.setValue("H"); // a Hypocenter
    sol.processingState.setValue(EnvironmentInfo.getAutoString()); //automatic or human?
    sol.validFlag.setValue(1);
    sol.horizDatum.setValue(datumHorizontal);
    sol.vertDatum.setValue(datumVertical);

    // set variables for Md if appropriate
    if (sol.magnitude != null && sol.magnitude.subScript.equals("d")) {
      sol.magnitude.source = sol.source;
      sol.magnitude.authority = sol.authority;
      sol.magnitude.method = sol.method;
      sol.codaList.clear();
    }

// parse the per-station results into the existing phaseList
    try {
      reader.readLine();
      String msg = reader.readLine();
      while (msg != null) {
        // DK CODE CHANGE 121802
        // Why are we using two sets of routines to parse the
        // arcfile station lines ???
        if (arcstn.parseArcStation(msg)) {
          outstr += (arcstn.getFormattedStationString() + "\n");
        }
        else {
          outstr += ("Bad Arc Station parseStatus" + "\n");
        }
        // End DK CODE CHANGE 121802

        // parse message into a NEW phase object
        Phase phNew = HypoFormat.parseArcToPhase(msg);

        // find matching phase in phaseList & transfer 'result' part of
        // returned phase (ie the 'assoc' object) into existing phase.

        if (phNew != null) {
          copyDependentData(phNew, phaseList);
        }
// DK No Md Code                  if(phNew.coda != null)
// DK No Md Code                   sol.codaList.add((Object)phNew.coda);

        reader.readLine();
        msg = reader.readLine();
      }

    }

    catch (InterruptedIOException exc) { // socket timed out
      message = "Socket timed out after " +
          SocketTimeoutMillis / 1000 + " seconds.";

      outstr += message + exc.getMessage();
      System.err.println(message + exc.getMessage());
      if (textArea != null)
        textArea.append(outstr);

      return false;
    }
    catch (IOException exc) {
      message = "Socket read error:";
      outstr += message + exc.getMessage() + "\n";
      System.err.println(message + exc.getMessage());
      if (textArea != null)
        textArea.append(outstr);

      return false;
    }

    // dump output to screen
    if (debug)
      System.out.println(outstr);

    if (sol.magnitude != null && sol.magnitude.subScript.equalsValue("d")) {
      Magnitude mag = sol.magnitude;
      Phase[] phases = phaseList.getArray();
      /**  DK No Md Code
                for(int i=0; i < phases.length; i++)
                {
                  if(phases[i].coda != null)
                  {
                    phases[i].coda.associateMag(mag);
                  }
                }
       **/

    }

    //dump output to text area
    if (textArea != null)
      textArea.append(outstr + "\n");

    message = "Location successful.";

    return true;

  }

  /** Find the original phase that returned in the Location output and copy all
   the Solution dependent values to the original phase. */

  protected void copyDependentData(Phase newPhase, PhaseList pl) {
    //    if (debug) System.out.println ("copy: newPhase= "+ newPhase.toString());
    // find a matching phase
    Phase oldPhase = pl.getPhaseLike(newPhase); // does NOT require association

    if (oldPhase == null)
      return; // no match
    //    if (debug) System.out.println ("copy: oldPhase= "+ oldPhase.toString());

    // copy stuff that depends on the solution (dist, rms, etc.)
    oldPhase.copySolutionDependentData(newPhase);
    //    if (debug) System.out.println ("copy: oldPhase= "+ oldPhase.toString());

  }

  /**
   * Write string to socket as a message. A message is variable length terminated
   * with '\n' */
  public boolean writeMessage(String msg) {
    String terminator = "\n";

//    System.out.println ("|"+msg+"|");	// debug

    String strOut = new String(msg + terminator); // append the terminator

    try {
      streamOut.write(strOut.getBytes());
    }
    catch (IOException exc) {
      message = "Socket write error.";
      System.err.println("Socket write error:" + exc.getMessage());
      return false;
    }

    return true;

  }

  /**
   * Read message from socket. A message is variable length terminated with '\n'.
   * Pass IOExeceptions back up to the caller.
   */
  protected String readMessage() throws IOException {

    int terminator = (int) '\n'; // "\n"

    byte[] bytes = new byte[4096];
    int intRead = 0;

// byte[] b = new byte[1];
    int byteCount = -1;
    //    try
    //    {
    // TCP is a stream protocol :. must read one byte at a time and look for
    // terminator Note that the terminator is NOT include in the message
    // returned to the caller
    /*BufferedReader reader = new BufferedReader(new InputStreamReader(streamIn));
         String lineString = reader.readLine();
         if(lineString != null)
      ;
         reader.readLine();
         lineString = reader.readLine();
         while(lineString != null){
      //
      reader.readLine();
      lineString = reader.readLine();
         }
     */
    while ( (intRead = streamIn.read()) != -1) {

      if (intRead == terminator) {
        if (byteCount > 0) {
          break; // terminator - bail
        }
        else {
          continue;
        }
      }

      bytes[++byteCount] = (byte) intRead;

      //System.out.println (intRead + " " + new String(bytes, 0, byteCount) );

      if (byteCount == bytes.length)
        break; // buffer is full
    }
    /*    }
      catch (InterruptedIOException exc)		// socket timed out
       {
        System.err.println ("Socket timed out after "+
          SocketTimeoutMillis/1000+" seconds.");
       }
      catch (IOException exc)
       {
        System.err.println ("Socket read error:" + exc.getMessage() );
       }
     */
    // socket closed :. broken message(?)
    if (intRead == -1 || byteCount == -1)
      return (String)null;

//    System.out.println ("+"+msg+"+");	// debug

    // DK DEBUG 071902
    String sInMsg = new String(bytes, 0, byteCount);
    System.out.print("\n<<<" + sInMsg + ">>>\n");

    return (sInMsg); // convert byte[] -> String
  }

  /**
   * Set the optional JTextArea where output will be directed.
   */
  public void setJTextArea(JTextArea textArea) {
    this.textArea = textArea;
  }

/// --------------------------------------------------------------------------
  /**
   * Main for testing
   */

  public static void main(String args[]) {

    int evid;

    // switch for debugging
    boolean commitIt = false;

    if (args.length <= 0) { // no args
      System.out.println("Usage: java LocationEngineHypoInverse [evid])");

      //evid = 9526852;
      evid = 13812160;

      System.out.println("Using evid " + evid + " as a test...");

    }
    else {

      Integer val = Integer.valueOf(args[0]); // convert arg String
      evid = (int) val.intValue();
    }

    JiggleProperties props = new JiggleProperties("properties");

    DbaseConnectionDescription dbConn = props.getDbaseDescription();
    // The data source is static
    //	DataSource ds = new DataSource(url, driver, user, passwd, writeBackEnabled);
    DataSource ds = new DataSource(dbConn);

    String locEngAddr = props.getProperty("LocationEngineHypoInverseAddress");
    int locEngPort = props.getInt("LocationEngineHypoInversePort");

//locEngAddr = "boron.gps.caltech.edu";
//locEngPort = 8800;

    System.out.println("Making MasterView for evid = " + evid);

    MasterView mv = new MasterView(); // make MasterView
    mv.setWaveFormLoadMode(MasterView.LoadNone);
    mv.defineByDataSource(evid);

    Solution sol = mv.solList.getSelected();

    System.out.println("--- Before location ------------------------------");
    System.out.println(sol.fullDump());
    System.out.println("--------------------------------------------------");

    //	String address = "boron.gps.caltech.edu";
    //	int port = 6500;

    LocationEngineHypoInverse locEng = new LocationEngineHypoInverse(locEngAddr,
        locEngPort);

    //	boolean status = locEng.solve(sol, mv.phaseList);
    boolean status = locEng.solve(sol);
    sol.processingState.setValue("H");

    if (status) {
      System.out.println("--- After Location -------------------------------");
      System.out.println(sol.fullDump());
      System.out.println("--------------------------------------------------");
      //	sol.phaseList.dump();

      if (commitIt) {
        System.out.println("Committing solution...");
        System.out.println("Message = " + locEng.getMessage());
        //		sol.commit();
      }
      else {
        System.out.println("NOT Committing solution...");
      }

    }
    else {

      System.out.println("Solution failed.");
      System.out.println(locEng.getMessage());
    }

    sol.depthFixed.setValue(true);
    sol.locationFixed.setValue(true);

    sol.depth.setValue(6.0);
    status = locEng.solve(sol);

    if (status) {
      System.out.println(
          "--- After Location () fixed Z -------------------------------");
      System.out.println(sol.fullDump());
      System.out.println("--------------------------------------------------");

    }
    else {

      System.out.println("Solution failed.");
      System.out.println(locEng.getMessage());
    }
  }

} // end of class

⌨️ 快捷键说明

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