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

📄 hypoformat.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 }

/**
 * Return a time string of the form: "YEARMODYHRMN SSSS". Seconds are to 2 decimals with no "."
 */
 public static String arcTimeString (double dt) {
  return ( arcYMDHMString(dt) + " " + arcSecString(dt) );
 }

/**
 * Return a time string of the form: "YEARMODYHRMN"
 */
 public static String arcYMDHMString (double dt)  {

/*
  SimpleDateFormat fmt
          = new SimpleDateFormat ("yyyyMMddHHmm");

// * 1000.0 for millisecs
  Date date =  new Date( (long) (dt * 1000.0) );

  String stime = fmt.format(date);
      return ( stime );
*/
     DateTime datetime = new DateTime(dt);
     return datetime.toDateString("yyyyMMddHHmm");

   }


/** Return a string for the epoch time with only hour/minute/second as required
 *  in the Hypoinverse terminator format. Ex: "HHmmssss". */
  public static String arcTerminatorTime(double dt) {

     String str = arcYMDHMString(dt) + arcSecString(dt);  // "yyyyMMddHHmmssss"
     return str.substring(8);
  }


/**
 * Return a time string of the form: "SSSS" with no decimal point.
 */
 public static String arcSecString (double dt) {

  return to42String( (new DateTime (dt)).getDoubleSecond() );

   }


/**
 * Make a Hypoinverse archive terminator line from a Solution object.
 * Note that the format uses Fortran style floating point format in some fields.
 * For example an "f4.2" field will appear like "3247" and be interpreted as
 * "32.47". <p>

 <tt>
   1         2         3         4         5         6         7
1234567890123456789012345678901234567890123456789012345678901234567890
      i2i2f4.2i2 f4.2i3  f4.2 f5.2                            i10
      hrmnsecsLT minsLON minszzzzz                            IDnumberxx
      0218152533 3050117 4512  600                            9876543
 </tt>
 */
    static public String toTerminatorString (Solution sol) {

    return toTerminatorString(sol, false, false, false);
     }

/**
 * Make a Hypoinverse archive terminator line from a Solution object.
 * If 'fixZ' is true the depth is fixed and will not be changed by the location process.
 * If 'fixLoc' is true both the location and depth are fixed but the origin time is
 * solved for.
 * If both are false, all parameters are solved for.
 * If 'trialLoc' is true the Solution (lat, lon, z and origin time) is used as
 * a trial (beginning) location by the location process. <p>
<tt>
   1         2         3         4         5         6         7
1234567890123456789012345678901234567890123456789012345678901234567890xxi2i2f4.2i2 f4.2i3  f4.2 f5.2                            i10
^^^^xxhrmnsecsLT minsLON minszzzzz                            IDnumberxx
      0218152533 3050117 4512  600                            9876543

Examples:
fixLoc = false, fixZ = false
                                                              9223372
fixLoc = true, fixZ = true
              33 4015116 5965-0.03X                           9223372
fixLoc = true, fixZ = false
              33 4015116 5965 0.03X                           9223372
fixLoc = false, fixZ = true
                             -0.03                            9223372
</tt>
 */
 static public String toTerminatorString (Solution sol,
                                          boolean fixLoc,
                                          boolean fixZ,
            boolean trialLoc) {

    StringBuffer sb = new StringBuffer(73);

    sb = sb.append ("      ");

    if (sol == null) return sb.toString();        //

    Format d2  = new Format("%2d");
    Format d3  = new Format("%3d");
    Format f52 = new Format("%5.2f");
    Format f42 = new Format("%4.2f");

//    sb = sb.append ("        ");  // trial time would go here (not used)
    sb = sb.append(arcTerminatorTime(sol.datetime.doubleValue()));
    LatLonZ latlonz = sol.getLatLonZ();

      double depth = Math.abs(latlonz.getZ());  // returns 0.0 if null
      if (fixZ) {
          depth = -depth;              // "-" indicates fixed
          if (depth == 0.0) depth = -0.01;  // Hypo no comprende -0.0
      }

      if ((fixLoc || trialLoc) && !latlonz.isNull()) {              // fix loc
         sb = sb.append(d2.form(latlonz.getLatDeg())+" ");
         sb = sb.append(to42String(latlonz.getLatMin()));
         sb = sb.append(d3.form(Math.abs(latlonz.getLonDeg()))+" ");
         sb = sb.append(to42String(latlonz.getLonMin()));
         sb = sb.append(f52.form(depth));
      } else {
         sb = sb.append("               ");
         if (fixZ) {                                  // fix Z only
           sb = sb.append(f52.form(depth));
         } else {                                     // don't fix nuthin'
           sb = sb.append ("     ");
         }
      }

      if (fixLoc && !latlonz.isNull()) {
         sb = sb.append ("X");    // any non-blank char here means fix location
      } else {
         sb = sb.append (" ");
      }

    if (!sol.id.isNull())
          sb = sb.append("                           "+sol.id.toString());

    return sb.toString();
 }

 /** Format seconds in Hypoinverse F4.2 style with no decimal point.
  *  For example: "12.8364" = "1284"*/
 protected static String to42String(double secs) {

    Format d2  = new Format("%02d");

    int   whole = (int) secs;               // casting truncates
    double frac = (secs - whole) * 100.0;

    return d2.form(whole) + d2.form( (int) Math.rint(frac));

 }
/**
 * Make a Hypoinverse2000 "summary header" line from a Solution object <p>
 <tt>
    1         2         3         4         5         6         7         8         9        10        11        12        13
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
199903080408538932 4205120  700    3  0 54329197 309223879900 43 29900  0   2659 -  098939893 71   0   0  0  0HAD      71    0  0   0  0         0   0   0   0   0
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
yearmodyhrmnseccLT minsLON minszzzzzMagNphGapDmnRmssAziDpSize

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>
 */
    static public String toSummaryString (Solution sol) {

  if (sol == null) return new String("    ");
  return "      ";	    /// obviously not done yet here
    }

/**
 * Format the channel as a Hypoinverse #2 station data format string.
         |         |         |         |         |         |         |         |
12345678901234567890123456789012345678901234567890123456789012345678901234567890
                                      xxxx3.1
GLA   CI  HHZ  33  0.0520N114  0.8270E   00.0  P  0.00  0.00  0.00  0.00 0  0.00
BAR   CI  HLE  32 40.8000 116 40.3300  496.0 A 0.00 0.00 0.00 0.00 1 0.00
BAR   CI  HLN  32 40.8000 116 40.3300  496.0 A 0.00 0.00 0.00 0.00 1 0.00
BAR   CI  HLZ  32 40.8000 116 40.3300  496.0 A 0.00 0.00 0.00 0.00 1 0.00
BAR2  CI  EHZ  32 40.8000 116 40.3300  496.0 A 0.00 0.00 0.00 0.00 1 0.00
BAR2  CI  VHZ  32 40.8000 116 40.3300  496.0 A 0.00 0.00 0.00 0.00 1 0.00
 */
public static String toH2StationString(Channel chan) {

    StringBuffer sb = new StringBuffer(82);

    Format d2 = new Format("%2d");
    Format d3 = new Format("%3d");
    Format f52 = new Format("%5.2f");
    Format f62 = new Format("%6.2f");
    Format f74 = new Format("%7.4f");

    ChannelName cn = chan.getChannelName();

    String str = cn.getSta();
    if (str.length() > 5) str = str.substring(0,5);
    sb = sb.append ( new Format("%-5s ").form(str) );

    str = cn.getNet();
    if (str.length() > 2) str = str.substring(0,2);
    sb = sb.append ( new Format("%-2s  ").form(str) );

    str = cn.getSeedchan();
    if (str.length() > 3) str = str.substring(0,3);
    sb = sb.append ( new Format("%-3s  ").form(str) );

/*
    try {
      sb = sb.append(cn.getSta().substring(0,5)+" ");
    }
    catch  (StringIndexOutOfBoundsException e) {}

    try {
      sb = sb.append(cn.getNet().substring(0,2)+" ");
    }
    catch  (StringIndexOutOfBoundsException e) {}
    sb = sb.append(' ');          // optional 1-letter comp code
    try {
      sb = sb.append(cn.getChannel().substring(0,3)+" ");
    }
    catch  (StringIndexOutOfBoundsException e) {}

    sb = sb.append(' ');          // optional sta weight code code
*/

// lat/lon

    sb = sb.append(d2.form(Math.abs(chan.latlonz.getLatDeg())) + " ");
    sb = sb.append(f74.form(chan.latlonz.getLatMin()));
    if (chan.latlonz.getLat() > 0) {
       sb = sb.append('N');          // North
    } else {
       sb = sb.append('S');          // South
    }

    sb = sb.append(d3.form(Math.abs(chan.latlonz.getLonDeg())) + " ");
    sb = sb.append(f74.form(chan.latlonz.getLonMin()));
    if (chan.latlonz.getLon() > 0) {
       sb = sb.append('E');
    } else {
       sb = sb.append('W');
    }

    sb = sb.append( new Format("%4d").form( (int) (chan.latlonz.getZ()*1000.0))  );   // elevation, km-> m (not used)

    sb = sb.append( new Format("%3.1f").form(0.0) );   // period

    sb = sb.append("  P ");   // space, primary model, remark

    sb = sb.append( f52.form(0.0) + " ");   // P-delay #1
    sb = sb.append( f52.form(0.0) + " ");   // P-delay #2

    sb = sb.append( f52.form(0.0) + " ");   // Amp corr & weight

    sb = sb.append( f52.form(0.0) + " ");   // mag corr. & wt

    sb = sb.append( "0" );   // inst type code

    sb = sb.append( f62.form(0.0) + "  ");   // Cal factor & comp extension

    return sb.toString();
}

/**
 * Parse the  Hypoinverse2000 "summary header" line and and return a new Solution object <p>
 */
public static Solution parseArcSummary (String str)
{
    Solution sol = Solution.create();
    parseArcSummary (sol, str);

    return sol;
}
/**
 * Parse the  Hypoinverse2000 "summary header" line into an existing Solution object. <p>
 * This will only replace those values in the Solution that are returned by Hypoinverse. In
 * particular the orid, evid, commid, Event and Magnitude objects of the Solution are left
 * unchanged. Other fields are not modified because that info is not in the Hypoinverse
 * output, e.g. authority, source, quality, type, etype, errorLat, errorLon, etc.
 */

public static Solution parseArcSummary (Solution sol, String str) {

    final double f100 = (float) 100.0;
    final double f60  = (float) 60.0;

// Only use the evid from Hypoinverse if there isn't one already
    if (sol.id.longValue() <= 0) sol.id.setValue(parseInt(str, 136, 146) );

// Origin time
    sol.datetime.setValue(parseArcSummaryTime(str));

// Latitude
    double deg = parseVal(str, 16, 18);
    double min = (double) parseInt(str, 19, 23) / f100;	// f4.2 :. /100
    double xlat = deg + ( min / f60);
    String hemi = str.substring(18,19);  // "S" for south, BLANK otherwise!
    if (hemi.equalsIgnoreCase("S")) xlat = -xlat;

// Longitude
    deg = parseVal(str, 23, 26);
    min = (double) parseInt(str, 27, 31) / f100;		// f4.2 :. /100
    // WARNING: Hypoinverse does NOT follow its own rules. The summary line returns
    // positive longitude and does NOT put "E" in the line. :. must kludge here.
    double xlon = -(deg + ( min / f60));
    hemi = str.substring(26,27);         // "E" for south, BLANK otherwise!
    if (hemi.equalsIgnoreCase("E")) xlon = -xlon;

// Z
    double xz = parseInt(str, 31, 36) / f100;	// f5.2, in Schema positive depth is down.

    sol.setLatLonZ(xlat, xlon, xz);

// Location parameters
    sol.usedReadings.setValue(parseInt(str, 39, 42));	// P & S w/ weights > 0.1
    //    sol.totalReadings.setValue(parseInt(str, 39, 42));	// P & S w/ weights > 0.1
    sol.totalReadings.setValue(sol.phaseList.size());	// total associated phases
    sol.gap.setValue(parseVal(str, 42, 45));
    sol.distance.setValue(parseVal(str, 45, 48));
    sol.rms.setValue(parseVal(str, 48, 52) / f100);

// TODO: parse more from OriginError table?

    sol.sReadings.setValue(parseInt(str, 82, 86));
    sol.errorHoriz.setValue(parseVal(str, 85, 89) / f100);
    sol.errorVert.setValue(parseVal(str, 89, 93) / f100);
    sol.firstMotions.setValue(parseInt(str, 93, 96));

    // EventQuality requires errorVert & errorHoriz
    sol.quality.setValue(EventQuality.getValue(sol));

    sol.crustModel.setValue(str.substring(110, 113));

⌨️ 快捷键说明

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