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

📄 mca.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            double testResult = Math.min(loDiff,hiDiff)/range;
            boolean revise = (testResult > CONFIDENCE_TEST[count]);
            if (revise) {
                codaArray[sorted[index]].getChannelMag().weight.setValue(0.);
                currentSol.removeCoda(codaArray[sorted[index]]);
            }
            if (debug)
                System.out.println("    reject magnitude: " +codaArray[sorted[index]].getChannelMag().value.doubleValue()+
                    " " + getStnChlNameString(codaArray[sorted[index]].getChannelObj()) +" " + revise);
        }
        return currentSol.codaList.getArray();
    }

    protected org.trinet.jasi.Coda [] rejectChannelsByMag(Magnitude mag, org.trinet.jasi.Coda [] codaArray) {
        int count = codaArray.length; // note better to use a statistical "Q-Test" for 10 or fewer samples
        double magValue = mag.value.doubleValue();
        for (int idx=0; idx < count; idx++) {
            boolean revise = false;
            ChannelMag chanMag = codaArray[idx].getChannelMag();
            double chanMagValue = chanMag.value.doubleValue();
            // What count value would be better than 30, anybody know ?
            //if (count < 30) revise = (Math.abs(summaryMagStats.mean - chanMagValue)/magValue > 3.3); // 4d rule 99.5%
            //else
            revise = (Math.abs(magValue - chanMagValue) > MAG_STD_DEVIATION_MULTIPLIER*mag.error.doubleValue());
            if (debug)
                System.out.println("    reject magnitude: " +chanMagValue+ " " +
                    getStnChlNameString( codaArray[idx].getChannelObj() ) +" " + revise);
            if (revise) {
                chanMag.weight.setValue(0.);
                currentSol.removeCoda(codaArray[idx]);
            }
        }
        return currentSol.codaList.getArray();
    }

    protected org.trinet.jasi.Coda [] rejectChannelsByDistance(Magnitude mag, org.trinet.jasi.Coda [] codaArray) {
        int count = codaArray.length;
        double magValue = mag.value.doubleValue();
        for (int idx=0; idx < count; idx++) {
            boolean revise = false;
            double distance = codaArray[idx].getDistance();
            if (isOutOfRange(magValue, distance)) {
                if (debug)
                    System.out.println("    reject distance : " +distance+ " " +
                         getStnChlNameString(codaArray[idx].getChannelObj()));
                revise = true;
            }
            if (revise) {
                codaArray[idx].getChannelMag().weight.setValue(0.);
                currentSol.removeCoda(codaArray[idx]);
            }
        }
        //if (verbose) System.out.println();
        return currentSol.codaList.getArray();
    }

    protected boolean isOutOfRange(double magValue, double distance) {
        boolean assertion = false;
        if (magValue < 1.4) {
           if (distance > 60.) assertion = true;
        }
        else if (magValue < 2.0) {
           if (distance > 120.) assertion = true;
        }
        else if (magValue < 2.5) {
           if (distance > 240.) assertion = true;
        }
        else if (magValue < 3.0) {
           if (distance > 320.) assertion = true;
        }
        return assertion;
    }

    public static PrintStream initLogStream(String logFileName) {
        PrintStream logStream = null;
        if (logFileName != null) {
            try {
                System.out.println("MCA logging output to file: " + logFileName);
                logStream = new PrintStream(new FileOutputStream(logFileName));
                System.setOut(logStream);
                System.setErr(logStream);
                System.out.println("Name of MCA log file: " + logFileName);
            }
            catch(IOException ex) {
                ex.printStackTrace();
            }
            catch(SecurityException ex) {
                ex.printStackTrace();
            }
        }
        return (logStream == null) ? System.out : logStream;
    }

    public void printOutputStreamHeader(PrintStream logStream) {
        logStream.println("MCA message logging starts at " + new java.util.Date().toString());
    }

    protected void initDbSource() {
        if (getDefaultConnection() == null) {
            System.out.println("Default db connection is null ... creating connection: ");
            //dataSource=new DataSource(config.dbURLText,config.dbDriverText,config.dbUserText,config.dbPasswordText,true);
            dataSource = new DataSource(JDBCConnect.createDefaultConnection(props), true);
        }
        else System.out.println("Default db connection is not null ... using connection: ");
        System.out.println(dataSource.toBlockString());
    }

    protected void initEnvironmentInfo() {
        String appName     = EnvironmentInfo.getApplicationName();
        String networkCode =  EnvironmentInfo.getNetworkCode();
        if (NullValueDb.isBlank(appName) || appName.equalsIgnoreCase("unknown")) EnvironmentInfo.setApplicationName("MCA");
        if (NullValueDb.isBlank(networkCode)) EnvironmentInfo.setNetworkCode("CI");
        if (verbose) System.out.println(EnvironmentInfo.getString());
    }

    protected List getEventIdList(String idFileName) {
        logStream.println("MCA event id file: " + idFileName);
        ArrayList idList = new ArrayList();
        try {
            BufferedReader idStream = new BufferedReader(new FileReader(idFileName));
            String idString = null;
            while (true) {
                idString = idStream.readLine();
                if (idString == null) {
                    idStream.close();
                    break;
                }
                idList.add(Long.valueOf(idString));
            }
        }
        catch (IOException ex) {
            ex.printStackTrace();
            System.out.println("Error processing event id input file:" + idFileName);
        }

        return idList;
    }

    protected boolean processEventById(long evid) throws JasiCommitException {
        boolean status = calcSummaryMagForEvid(evid, false);
        try {
            if (config.commitOn) {
                commit();
                dataSource.commit();
            }
        }
        catch (JasiCommitException ex) {
            ex.printStackTrace();
            System.out.println("Attempting rollback of database updates");
            try {
                getDefaultConnection().rollback();
            }
            catch (java.sql.SQLException sqlEx) {
                sqlEx.printStackTrace();
            }
            status = false;
        }
        benchMarkCodaCalculation();
        return status;
    }

    protected final void benchMarkCodaCalculation() {
        if (benchmark != null) {
            benchmark.print("\nMCA BenchMark solution: " +currentSol.id.longValue()+ " calcCodaCount: " +calcCount+ " ");
            benchmark.reset();
        }
    }

    protected boolean processEventIdList(List idList) {
        int idCount = idList.size();
        if (idCount <= 0) {
            resultsMessage = "MCA found no event ids in input file, must specify one id per line in input file";
            System.out.println(resultsMessage);
            return false;
        }
        if (debug) System.out.println(idCount + " count MCA ids:" + idList.toString());

        try {
          for (int idx = 0; idx < idCount; idx++) {
            processEventById( ((Long) idList.get(idx)).longValue());
          }
        } catch (JasiCommitException ex) {}

        if (verbose) System.out.println("MCA total processing time: " +
                EpochTime.elapsedTimeToText((int) (System.currentTimeMillis() - mca.startMillisecs)/1000));
        return true;
    }

    public static double calcMcaMag(long evid) {
        if (MCA.mca == null) {
            System.out.println("Initializing new MCA");
            initMCADefault();
        }
        try {
           MCA.mca.processEventById(evid);
        } catch (JasiCommitException ex) {}
        return MCA.mca.getSummaryMagnitudeValue();
    }

    protected void closeLog() {
        logStream.close(); // does a flush
    }

    protected void closeDataSource() {
        if (dataSource != null) {
            dataSource.close();
            dataSource = null;
        }
    }

    protected static void initMCADefault() {
        MCA.initMCA(System.out, MCA.mca.DEFAULT_PROPERTY_FILE_NAME, null);
    }

    protected static void initMCA(PrintStream outStream, String propertyFileName, ChannelList channelList) {
        MCA.mca = new MCA();
        MCA.mca.logStream = (outStream == null) ? System.out : outStream;
        MCA.mca.printOutputStreamHeader(MCA.mca.logStream);
        MCA.mca.benchmark = new BenchMark("MCA BenchMark ");
        MCA.mca.initByProperty(propertyFileName);
        MCA.mca.initDbSource();
        MCA.mca.initEnvironmentInfo();
        MCA.mca.setChannelList(channelList);
    }

    public static final MCA createMCA() {
        return createMCA(null, null, null);
    }
    public static final MCA createMCA(String propFileName) {
        return createMCA(propFileName, null, null);
    }
    public static final MCA createMCA(String propFileName, String logFileName) {
        return createMCA(propFileName, logFileName, null);
    }
    public static final MCA createMCA(String propFileName, String logFileName, ChannelList channelList) {
        PrintStream logStream = (logFileName == null) ? System.out : MCA.mca.initLogStream(logFileName);
        MCA.initMCA(logStream, propFileName, channelList);
            logStream.println("MCA Property file: " + propFileName);
        return MCA.mca;
    }

// Method below is for testing db SQLPlus java function implementation like "main"
    public static final void processByConfiguration(String propFileName, String eventIdFileName, String logFileName) {
        processByConfiguration(propFileName, eventIdFileName, logFileName, false);
    }

    public static final void processByConfiguration(String propFileName, String eventIdFileName, String logFileName,
                                             boolean closeDataSource) {
        MCA mca = MCA.createMCA(propFileName, logFileName);
        mca.processEventIdList(mca.getEventIdList(eventIdFileName));
        System.out.println("Total MCA processing time: " +
                EpochTime.elapsedTimeToText((int) (System.currentTimeMillis() - mca.startMillisecs)/1000));
        if (closeDataSource) {
            mca.closeDataSource();
            mca.closeLog();
        }
    }

// temporarily override IF method to benchmark
    public int processSolution(Solution sol) {
        int status = super.processSolution(sol);
        benchMarkCodaCalculation();
        return status;
    }

//batch mode or debug
    public static final void main(String [] args) {
        int nargs = args.length;
        if (nargs < 2) {
             System.err.println("arguments: propFilePathName evidFilePathName [logfilePathName]");
             System.err.println("example: MCA  mca.properties mca.ids mca.log");
             System.exit(0);
        }
        String logFileName = (nargs > 2) ? args[2] : MCA.DEFAULT_LOG_FILE_NAME;
        MCA.processByConfiguration(args[0], args[1], logFileName, true);
        System.exit(0);
    }

} // end of MCA class

⌨️ 快捷键说明

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