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

📄 hypoformat.java

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

    // These parameters are not available from the Hypoinverse format
    // Authority, subsource
    // Other problems:
    // Crustal model is char[3], we expect int
    // "last authority" is one char, we expect FDSN char[2]

    // magnitude info not read yet
    //  grab duration magnitude data and build new Md mag

/*
    Number num;
    if((num = parseNumber(str, 70, 73)) != null)
    {
       Magnitude mag = Magnitude.create();
       mag.subScript = new DataString("d");
       mag.value = new DataDouble(num.doubleValue()/100);

       if((num = parseNumber(str, 100, 105)) != null)
       {
         mag.usedStations = new DataLong((num.intValue()+9.9)/10);  // approx
       }

       // mad (Median Absolute Difference)  -- could be used for quality
       if((num = parseNumber(str, 107, 110)) != null)
       {
         mag.error = new DataDouble(num.doubleValue() / 100.0);  // approx
       }
       mag.sol = sol;
       mag.codaList = sol.codaList;
       mag.source = sol.source;
       sol.magnitude = mag;
    }
*/

    return sol;

}

/**
 * Parse the P-wave time in the station Archive string
 */
public static double parseArcPTime (String str)
{
    double epochSecs = HypoFormat.parseArcYMDHM(str.substring(17,29));

    int sec  = (int) parseVal (str, 29, 32);      // whole seconds
    int frac = (int) parseVal (str, 32, 34);     // fractional 0.01 seconds

    return epochSecs + (double) sec + (double)frac/100.0;     // convert to epoch time
}

/**
 * Parse the S-wave time in the station Archive string
 */
public static double parseArcSTime (String str)
{
    double epochSecs = HypoFormat.parseArcYMDHM(str.substring(17,29));

    int sec  = (int) parseVal (str, 42, 44);      // whole seconds
    int frac = (int) parseVal (str, 44, 46);     // fractional 0.01 seconds

    return epochSecs + (double) sec + (double)frac/100.0;     // convert to epoch time
}

/**
 * Return epoch second of time string up to the minute. Does NOT include the seconds part
 * which varies with context. For station lines you need to pass <str>.substring(17,29).
 * This is the "base minute" of the "card".
 */
public static double parseArcYMDHM(String str) {

    int yr = parseInt (str,  0,  4);
    int mo = parseInt (str,  4,  6) - 1;  // in Java-land January = 0, etc.
    int dy = parseInt (str,  6,  8);
    int hr = parseInt (str,  8, 10);
    int mn = parseInt (str, 10, 12);

// Y2K note: Date expects 'yr' to be "years since 1900", but Calendar expects 4 digit year.
// January is month '0'
// If you try to use GMT time zone here, Java will kindly "correct" to local time later when
// you use SimpleDateFormat and subtract 7 or 8 hours. THIS ISN'T WHAT WE WANT. So, just use
// default and it should be OK.

//    TimeZone gmt = TimeZone.getTimeZone("GMT");
/*
    TimeZone gmt = TimeZone.getDefault();
    GregorianCalendar cal = new GregorianCalendar(gmt);

    cal.set(yr, mo-1, dy, hr, mn, 0);                  // convert to Java time base

    long epochMillis = cal.getTime().getTime();
*/
    DateTime dt = new DateTime(yr, mo, dy, hr, mn, 0.0);

    return dt.getEpochSeconds();

}

/**
 * Parse the Archive summary line format string. Note: its slightly different from the
 * time in the station lines.
 * <tt>
 * "199902101612100333 4015116 5965    3  0 31155  3  2316273 10134516  58  0     28 #  2  56  97 37   0   0  0  0HAD      39    0  0   0  0  13761428   0   0   0   0"
 </tt>
 *
 */
public static double parseArcSummaryTime (String str)
{
    double epochSecs = HypoFormat.parseArcYMDHM(str);
    int sec  = parseInt (str, 12, 14);	// whole seconds (f4.2) Note:sta fmt is (f5.2)
    int frac = parseInt (str, 14, 16);	// fractional seconds

    return epochSecs + (double) sec + (double)frac/100.0;     // convert to epoch time
}

/**
 * Convert the specified field in the string to a value. First field is 0.
 */
/* Note: "Double" is a class & "double" is a type, thus
 *        this weirdness
 */
   public static double parseVal (String str, int start, int stop)
    {
  String substr = "";

  try
  {
      substr = str.substring(start, stop);

      Double val = Double.valueOf(substr.trim());
      return (val.doubleValue());
  }
  catch (NumberFormatException exc)
  {
      System.out.println ("Double format conversion error: /" + substr+"/");
  } catch  (StringIndexOutOfBoundsException e) {
      System.out.println ("String out of bounds error: /" + str+"/");
  }
  return -1;
    }
/**
 * Convert the specified field in the string to a Number object. This allows a
 * return of 'null' if the string is blank.  */
   public static Number parseNumber (String str, int start, int stop)
    {
  String substr = "";

  try
  {
      substr = str.substring(start, stop);

      Double val = Double.valueOf(substr.trim());
      return (Number) val;
  }
  catch (NumberFormatException exc)
  {
      System.out.println ("Number format conversion error: /" + substr+"/");
  } catch  (StringIndexOutOfBoundsException e) {
      System.out.println ("String out of bounds error: /" + str+"/");
  }
  return null;
    }
/**
 * Convert the specified field in the string to an int value. First field is 0.
 */
   public static int parseInt (String str, int start, int stop)
    {
  String substr = "";

  try
  {
      substr = str.substring(start, stop);

      Integer val = Integer.valueOf(substr.trim());
      return (val.intValue());
  }
  catch (NumberFormatException exc)
  {
      System.out.println ("Integer format conversion error: /"+substr+"/");
  } catch (StringIndexOutOfBoundsException e) {
      System.out.println ("String out of bounds error: " + str);
  }
  return -1;  // well, ya gotta return somethin'
    }

/**
 * Parse a station list line in Hypoinverse format into a Channel object.
 * Returns null if there's a problem.
 */
/*
0         1         2         3         4         5         6         7         8
012345678901234567890123456789012345678901234567890123456789012345678901234567890
ABL  34 50.91N119 13.50W1975        0.0                            GSP VHZ 2252355    30  1700

 */

  public static Channel parseStationLine (String str)
  {
  double deg, min, lat, lon, z;

  Channel ch = Channel.create();

//TODO: make this general!!

        ch.setNet(EnvironmentInfo.getNetworkCode());     // must assume
  ch.setSta(str.substring(0, 5).trim());	// trim blanks
  ch.setChannel(str.substring(71, 74).trim());

  ch.setSeedchan(ch.getChannel());	// kludge

// cull out obvious crap
  if ( ch.getSta().equals("") ) return null;
  if ( ch.getChannel().equals("???") ) return null;

  deg = parseVal (str, 5, 7);
  min = parseVal (str, 8, 13);
  lat  = deg + (min/60.0);
  if (str.substring(13, 14).equalsIgnoreCase("S")) lat *= -1.0;    // change sign

  deg = parseVal (str, 14, 17);
  min = parseVal (str, 18, 23);
  lon = deg + (min/60.0);
  if (str.substring(23, 24).equalsIgnoreCase("W")) lon *= -1.0;    // change sign

  z = parseVal (str, 24, 28);
  z = z/1000.0;			// m -> km

  // guard against bogus lines
  if (lat == 0.0 && lon == 0.0) return null;

  ch.latlonz.set(lat, lon, z);

  return (ch);
  }


/**
 * Parse a station list line in Hypoinverse archive format into a Channel object.
 * Returns null if there's a problem. */
/*
0         1         2         3         4         5         6         7         8
012345678901234567890123456789012345678901234567890123456789012345678901234567890
ABL   CI  EHZ  34 50.9100 119 13.5000 1975.0 A 0.00 0.00 0.00 0.00 1 0.00

 */

  public static Channel parseStationArcLine (String str)
  {
  double deg, min, lat, lon, z;

  Channel ch = Channel.create();

  ch.setNet (str.substring(6, 8).trim());
  ch.setSta(str.substring(0, 5).trim());	// trim blanks
  ch.setChannel(str.substring(10, 13).trim());

  ch.setSeedchan(ch.getChannel());	// kludge

// cull out obvious crap
  if ( ch.getSta().equals("") ) return null;
  if ( ch.getChannel().equals("???") ) return null;

  deg = parseVal (str, 15, 17);
  min = parseVal (str, 18, 25);
  lat  = deg + (min/60.0);

  deg = parseVal (str, 26, 29);
  min = parseVal (str, 30, 37);
  lon = deg + (min/60.0);
// kludge !!!!! Longitudes in the file are positive and have no hemisphere letter.
  lon *= -1.0;    // change sign

  z = parseVal (str, 38, 44);
  z = z/1000.0;			// m -> km

  // guard against bogus lines
  if (lat == 0.0 && lon == 0.0) return null;

  ch.latlonz.set(lat, lon, z);

  return (ch);

  }

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

public static void main (String[] arg) {

/*
       1         2         3         4         5         6         7         8         9        10        11
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
STATNnt cCMP pr  yearmodyhrmnseconPresPwtS-secSr sSrespek2pekmmSwtPdlySdlyDistAngADPerRCodaAzmDurMagPimpSimpSFX
QAL  CI VVHZ     199811120254    0   0  0 5709ES 2 301      0 0  0   0   01359 7000  0    0174  0  0   0   0
QAL  CI VVHZ     199811120254      301 50 5709ES 2                        1359              70
*/
    //String testarr = "MCV  NC VVHZ  PU0199806262007 4310  -9110    0   0   0      0 0  0   0   0  1616400  0  159297404  0 502   0WD ";

String testarr =
"QAL  CI VVHZ     199811120254    0   0  0 5709ES 2 301      0 0  0   0   01359 7000  0    0174  0  0   0   0   ";

String testorg =
"199902101612100333 4015116 5965    3  0 31155  3  2316273 10134516  58  0     28 #  2  56  97 37   0   0  0  0HAD      39    0  0   0  0  13761428   0   0   0   0";

// parse the string
    Phase ph = parseArcToPhase(testarr);

// reformat

    System.out.println (" in: |"+testarr);
    System.out.println ("out: |"+toArchiveString (ph));
    System.out.println (ph.toString());

    System.out.println("");

// solution summary
    Solution sol = parseArcSummary(testorg);

    System.out.println (" in: |"+testorg);
    System.out.println ("out: |"+toSummaryString(sol));
    System.out.println (sol.toSummaryString());

    System.out.println("");

// terminator variants
    System.out.println (HypoFormat.toTerminatorString(sol));
    System.out.println (HypoFormat.toTerminatorString(sol, true, true, false));
    System.out.println (HypoFormat.toTerminatorString(sol, true, false, false));
    System.out.println (HypoFormat.toTerminatorString(sol, false, true, false));
    System.out.println (HypoFormat.toTerminatorString(sol, false, false, true));
}


} // end of class

⌨️ 快捷键说明

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