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

📄 mca.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package org.trinet.util.magnitudeengines;
import java.io.*;
import java.sql.*;
import java.util.*;
import org.trinet.pcs.*;
import org.trinet.jasi.*;
import org.trinet.jasi.coda.*;
import org.trinet.jdbc.*;
import org.trinet.util.*;
import org.trinet.util.velocitymodel.*;
import org.trinet.jasi.TN.*;
import org.trinet.jasi.coda.TN.*;
import org.trinet.jdbc.JDBCConnect;

//  Creates/update the codaList and Magnitude members of Solution
public class MCA extends CodaMagnitudeGenerator implements TNCommitableIF {

/*
    protected static final static final String dbURLTextDefault          = "jdbc:oracle:thin:@k2.gps.caltech.edu:1521:k2db";
    protected static final static final String dbDriverTextDefault       = "oracle.jdbc.driver.OracleDriver";
    protected static final static final String dbUserTextDefault         = "trinetdb";
    protected static final static final String dbPasswordTextDefault     = "calgs";
    protected static final static final String defaultPropertyFile       = "MCA.properties";
*/
/*
    {
        this.channelCacheFileName = "McaChannelCache";
    }
*/
/*
    protected static final String DEFAULT_SQL_STRING =
         "SELECT " + ChannelData.QUALIFIED_COLUMN_NAMES + " FROM " +  ChannelData.DB_TABLE_NAME;
    protected String toChannelListSQLString(java.util.Date date) {
        if (date == null) return DEFAULT_SQL_STRING;
        return DEFAULT_SQL_STRING + " WHERE " + DataTableRow.toDateConstraintSQLWhereClause(ChannelData.DB_TABLE_NAME, date);
    }
*/
    protected double pTravelTime;
    protected double sTravelTime;

    protected static MCA mca;
    protected static final String DEFAULT_PROPERTY_FILE_NAME = "MCA.properties";
    protected static final String DEFAULT_LOG_FILE_NAME = "mca.log";
    public static final double MAG_STD_DEVIATION_MULTIPLIER = 2.0;

    protected PrintStream logStream;
    protected static DataSource dataSource; // could be a Connection to have multiple instances
    protected BenchMark benchmark;
    protected long startMillisecs = System.currentTimeMillis();

    Properties props;
    protected RuntimeSetup config = new RuntimeSetup();

    protected class EmptyCalibrationListException extends RuntimeException  {
        protected EmptyCalibrationListException () {
            super();
        }
        protected EmptyCalibrationListException (String message) {
            super(message);
        }
    }

    protected class RuntimeSetup {
        String generatorParmType;
        String solutionProcessingMode;
        boolean commitOn;
        boolean verboseOn;
        boolean filterOn;
        boolean debugOn;
        boolean logCodaCalc;
        boolean logMagResiduals;
        String dbURLText;
        String dbDriverText;
        String dbUserText;
        String dbPasswordText;

        List acceptChannelList;
        List filterChannelList;
        List summaryChannelList;

        int    minCodaCountForSummaryMag ;
        double codaStartOffsetSecs;
        double codaPrePTimeBiasOffsetSecs;

        long loadWaitTimeMillis;
        int  maxLoadingWaits;
        int  waveformCacheSize;
    }


// Constructors
    public MCA() {}

    public MCA(String propertyFilePathName) throws IllegalStateException {
        initByProperty(propertyFilePathName) ;
    }

    public MCA(
               CodaGeneratorParms codaGeneratorParms,
               PrimarySecondaryWaveTravelTimeGeneratorIF ttGenerator,
               CodaGeneratorIF codaGenerator
              ) {
        this.codaGeneratorParms = codaGeneratorParms;
        if (ttGenerator == null)
            throw new IllegalArgumentException("MCA constructor requires non-null traveltime calculator.");
        this.ttGenerator = ttGenerator;

        if (codaGenerator == null)
            throw new IllegalArgumentException("MCA constructor requires non-null coda calculator.");
        this.codaGenerator = codaGenerator;

        initCodaGenerator();

    }

    protected void initByProperty(String propertyFilePathName) throws IllegalStateException {
        if (propertyFilePathName == null) propertyFilePathName = DEFAULT_PROPERTY_FILE_NAME;
        boolean status = loadProperties(propertyFilePathName);
        if (! status)
            throw new IllegalStateException("Unable to load MCA configuration properties from file: " + propertyFilePathName);
        initIOState();
        initGenerators();
        initFilter();
        initSolutionProcessingMode();
    }

// class specific Initialization

    public void setConnection(Connection connection) {
        if (dataSource == null) dataSource =  new DataSource(connection, true);
        else dataSource.setConnectionInfo(connection);
    }

    public Connection getConnection() {
        return dataSource.getConnection();
    }

    public static Connection getDefaultConnection() {
        return dataSource.getConnection();
    }

    public Properties getConfigurationProperites() {
        return props;
    }

    protected void initIOState() {
        setVerbose(config.verboseOn);

        this.logCodaCalc = config.logCodaCalc;
        this.logMagResiduals = config.logMagResiduals;

        setDebug(config.debugOn);
        if (config.debugOn) {
           this.logCodaCalc = true;
           this.logMagResiduals = true;
        }
        //setAutoCommit(config.commitOn);
        //channelCacheFileName = "McaChannelCache";

        this.minCodaCountForSummaryMag          = config.minCodaCountForSummaryMag;
        this.codaStartOffsetSecs                = config.codaStartOffsetSecs;
        this.codaPrePTimeBiasOffsetSecs         = config.codaPrePTimeBiasOffsetSecs;
        this.maxSleepTimeMillis                 = config.loadWaitTimeMillis;
        this.maxSleepLoadingIterations          = config.maxLoadingWaits;
        this.maxWaveformCacheSize               = config.waveformCacheSize;
        if (maxWaveformCacheSize < 2) setWaveformCacheLoading(false);

    }
    protected void initSolutionProcessingMode() {
        if (config.solutionProcessingMode.equalsIgnoreCase("CALC_CODA_AND_SUMMARY_MAG")) {
            setSolutionProcessingMode(CodaSolutionProcessingMode.CALC_CODA_AND_SUMMARY_MAG);
        }
        else if (config.solutionProcessingMode.equalsIgnoreCase("CALC_CODA_ONLY")) {
            setSolutionProcessingMode(CodaSolutionProcessingMode.CALC_CODA_ONLY);
        }
        else if (config.solutionProcessingMode.equalsIgnoreCase("CALC_SUMMARY_MAG_USE_EXISTING_CODA")) {
            setSolutionProcessingMode(CodaSolutionProcessingMode.CALC_SUMMARY_MAG_USE_EXISTING_CODA);
        }
    }
    protected void initGenerators() {
        if (config.generatorParmType.equalsIgnoreCase("TEST")) {
            this.codaGeneratorParms = CodaGeneratorParms.SOCAL_TEST;
            this.codaGenerator      = new McaCodaGeneratorExp();
        }
        else {
            if (config.generatorParmType.equalsIgnoreCase("CUSP")) {
                this.codaGeneratorParms = CodaGeneratorParms.SOCAL_CUSP;
            }
            else if (config.generatorParmType.equalsIgnoreCase("DEFAULT")) {
                this.codaGeneratorParms = CodaGeneratorParms.SOCAL_DEFAULT;
            }
            this.codaGenerator = new McaCodaGeneratorTN();
        }

        this.ttGenerator   = new TTLayer(UniformFlatLayerVelocityModel.SOCAL_DEFAULT);
        initCodaGenerator();
    }

    protected void initFilter() {
        if (config.filterOn) {
            if (config.verboseOn) System.out.println("Butterworth filtering forward/reverse mode on");
            codaGenerator.setFilter(new org.trinet.util.FloatButterworthHighPassFilter(true));
            codaGenerator.enableFilter();
        }
    }

    protected void initCodaGenerator() {
        if (codaGeneratorParms == null) codaGeneratorParms.load();   //  retrieve coda algorithm parameters from ?
        if (verbose) System.out.println("CodaGeneratorParms: " + codaGeneratorParms.toString());
        CodaGeneratorTN generator = (CodaGeneratorTN) this.codaGenerator;
        generator.setResetOnClipping(codaGeneratorParms.resetOnClipping) ;
        generator.setMinGoodWindows(codaGeneratorParms.minGoodWindowsToTerminateCoda) ;
        generator.setMaxGoodWindows(codaGeneratorParms.maxGoodWindowsToTerminateCoda) ;
        generator.setCodaStartSignalToNoiseRatio(codaGeneratorParms.minSNRatioForCodaStart) ;
        generator.setCodaCutoffSignalToNoiseRatio(codaGeneratorParms.minSNRatioCodaCutoff) ;
        generator.setPassThruNoiseDecayAmpRatio(codaGeneratorParms.passThruNSRatio) ;
        generator.setWindowSize(codaGeneratorParms.windowSize) ;
        generator.setQFix(codaGeneratorParms.qFix) ;
    }

    protected boolean setProperties(String propFileName) {
        props =  new Properties();
        if (propFileName == null) return false;

        File file = new File(propFileName);
        boolean status = false;

        try {
            if (file.isAbsolute()) {
                props.load(new BufferedInputStream(new FileInputStream(propFileName)));  // requires io.FilePermission read
                status = true;
            }
            else {
                InputStream inStream = getClass().getResourceAsStream(propFileName);
                if (inStream != null) {
                    props.load(inStream); // allows load of database resource file
                    status = true;
                }
                else {
                    String fileName = System.getProperty("user.dir", ".") +
                                  System.getProperty("file.separator", "/") +
                                  propFileName;
                    props.load(new BufferedInputStream(new FileInputStream(fileName)));  // requires io.FilePermission read
                    status = true;
                }

            }
        }
        catch(FileNotFoundException ex) {
            ex.printStackTrace();
            System.out.println("MCA property file not found " + propFileName);
        }
        catch(IOException ex) {
            ex.printStackTrace();
            System.out.println("MCA error reading property file " + propFileName);
        }
        catch (SecurityException ex) {
            ex.printStackTrace();
            System.out.println("MCA no permission to read property file " + propFileName);
        }
        return status;
    }

    protected boolean loadProperties(String propertyFileName) {
        if (! setProperties(propertyFileName)) return false;

        config.dbURLText = props.getProperty("tpp.default.jdbc.URL");
        config.dbDriverText = props.getProperty("tpp.default.jdbc.driver");
        config.dbUserText = props.getProperty("tpp.default.jdbc.user");
        config.dbPasswordText = props.getProperty("tpp.default.jdbc.password");

        config.solutionProcessingMode = props.getProperty("processingMode", "CALC_CODA_AND_SUMMARY_MAG");
        config.generatorParmType = props.getProperty("generator", "TEST");
/*
        config.acceptChannelTypes = props.getProperty("acceptChan", "" );
        config.filterChannelTypes = props.getProperty("filterChan", "" );
        config.summaryChannelTypes = props.getProperty("summaryChan", acceptChannelTypes);
*/
        config.acceptChannelList  = createChannelTypeProcessingList(props.getProperty("acceptChan", "EHZ HHZ"));
        config.summaryChannelList = createChannelTypeProcessingList(props.getProperty("summaryChan", "EHZ"));

⌨️ 快捷键说明

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