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

📄 codatn.java

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

import org.trinet.jasi.*;

import java.util.*;
import java.sql.*;

import org.trinet.jasi.*;
import org.trinet.jdbc.*;
import org.trinet.jdbc.datatypes.*;
import org.trinet.jdbc.table.*;
import org.trinet.util.*;
import org.trinet.jasi.coda.*;
import org.trinet.jasi.coda.TN.*;
//  CodaTN.java
/**
* The CodaTN class contains data which relate the amplitude time decay
* of a seismic event's S-wave recorded by a station channel to an event magnitude.
<pre>
  There are two source states for Coda objects:
        1) those initialized with data read from the database, see getByXXX(...) methods.
           By convention, the Coda table rows are not deleted or updated,
           but a new AssocCoO or AssocCoM table row may be created.

        2) those newly created by an application, see create(...) methods.
           To preserve this data, it must be inserted into the Coda table,
           the AssocCoO table and if magnitude is defined, the AssocCoM table.
</pre>
*/
public class CodaTN extends org.trinet.jasi.Coda {
    /** Set flag true to enable debug output Strings printed to System.out. */
    protected static boolean debug = false;

    /**
    * Value determines which database operations are performed to preserve
    * the data by the commit() method.
    * True implies instance data were orginally initialized from a database
    * (see  getByXXX() methods).
    * @see #commit()
    */
    protected boolean fromDbase = false;

    /** Flags this object as modified and requiring a database update using commit().
    *   @see #commit()
    */
    protected boolean update = false;

    /** Value indicates data were initialized by a join of Coda and an associated table. */
    protected static int joinType;
    /** Value indicates data were initialized by a join of Coda and an AssocCoO table. */
    protected static final int Type_AssocCoO = 1;
    /** Value indicates data were initialized by a join of Coda and an AssocCoM table. */
    protected static final int Type_AssocCoM = 2;
    /** Value indicates data were initialized by a join of Coda and an AssocCoO table and AssocCoM. */
    protected static final int Type_Assoc = 3;


/** The start of SQL queries to get all rows from Coda table. */
    protected static String sqlPrefix = "Select " +
        org.trinet.jdbc.table.Coda.QUALIFIED_COLUMN_NAMES + " from Coda ";

/** The start of SQL queries to get all rows associated with a origin, joins Coda & AssocCoO tables */
    protected static String sqlPrefixByOrigin = "Select " +
        org.trinet.jdbc.table.Coda.QUALIFIED_COLUMN_NAMES + "," +
        AssocCoO.QUALIFIED_COLUMN_NAMES +
        " from Coda, AssocCoO where (Coda.coid = AssocCoO.coid) ";

/** The start of SQL queries to get all rows associated with a magnitude, joins Coda & AssocCoM tables */
    protected static String sqlPrefixByMag = "Select "+
        org.trinet.jdbc.table.Coda.QUALIFIED_COLUMN_NAMES + "," +
        AssocCoM.QUALIFIED_COLUMN_NAMES+
        " from Coda, AssocCoM where (Coda.coid = AssocCoM.coid) ";

/** The start of SQL queries to get all rows associated with a magnitude, joins Coda & AssocCoO, and AssocCoM tables */
    protected static String sqlPrefixByAssoc = "Select "+
        org.trinet.jdbc.table.Coda.QUALIFIED_COLUMN_NAMES + "," +
        AssocCoO.QUALIFIED_COLUMN_NAMES+ "," +
        AssocCoM.QUALIFIED_COLUMN_NAMES+
        " from Coda, AssocCoO, AssocCoM where (Coda.coid = AssocCoO.coid) AND (Coda.coid = AssocCoM.coid) ";

    /** Origin identifier, sequence number of an Origin table row. */
    protected DataLong orid = new DataLong();        // maps to Trinet schema AssocCoO.orid

    /** Coda identifier, sequence number of a Coda table row. */
    protected DataLong coid = new DataLong();        // maps to Trinet schema Coda.coid and AssocCoO.coid

// **** moved all below to Coda.java *****

/** Coda duration calculated from P-wave onset  (e.g. use q,a fitting 60mv cutoff ampi). */
    //    protected DataDouble tau = new DataDouble();     // maps to Trinet schema Coda.tau

/** Coda log(amp)-log(tau) line fit parameter when slope (q) is fixed and tau = 1. */
    //    protected DataDouble aFix = new DataDouble();    // maps to Trinet schema Coda.aFix

/** Coda line slope parameter determined by best fit of known calibration set of
    earthquake qFree data for known magnitudes. */
    //    protected DataDouble qFix = new DataDouble();    // maps to Trinet schema Coda.qFix

/** Coda log(amp)-log(tau) line fit parameter when slope (q) is free and tau =
    1. */
    //    protected DataDouble aFree = new DataDouble();   // maps to Trinet schema Coda.aFree

/** Coda line slope parameter determined by least absolute residual line fit of
    single events windowed time amp data. */
    //    protected DataDouble qFree = new DataDouble();   // maps to Trinet schema Coda.qFree

/**
* Default constructor protected, use factory create(...) methods to instantiate instance.
*/
    public CodaTN () { }

// Methods


    public static void setDebug(boolean value) {
        debug = value;
    }

/** Returns String identifying numeric solution, magnitude, origin, and coda sequence number identifiers. */
    public String idString() {
        StringBuffer sb = new StringBuffer(super.idString());
        sb.append(" Origin id: ").append(orid.toStringSQL());
        sb.append(" Coda id: ").append(coid.toStringSQL());
        return sb.toString();
    }

/** Returns String identifying data source and input configuration parameters for coda fit algorithm. */
    protected String inParmsString() {
        StringBuffer sb = new StringBuffer(super.inParmsString());
        sb.append(" fromDB: ").append(fromDbase);
        if (fromDbase) {
            sb.append(" join: ");
            if (joinType == Type_AssocCoO) sb.append("AssocCoO");
            else if (joinType == Type_AssocCoM) sb.append("AssocCoM");
            else if (joinType == Type_Assoc) sb.append("Assoc");
        }
        return sb.toString();
    }

/** Returns String describing the calculated coda fit parameters. */
    protected String outParmsString() {
        StringBuffer sb = new StringBuffer(super.outParmsString());
        sb.append('\n');
        sb.append(" aFix: ").append(aFix.toStringSQL());
        sb.append(" aFree: ").append(aFree.toStringSQL());
        sb.append(" qFix: ").append(qFix.toStringSQL());
        sb.append(" qFree: ").append(qFree.toStringSQL());
        sb.append(" tau: ").append(tau.toStringSQL());
        return sb.toString();
    }

//need to implement a this from the top of the jasi hierarchy down AWW :   public Object clone() {

/**
* Changes the coda phase descriptor if input is not equivalent to current descriptor.
* Sets the instance update flag status true, if descriptor is changed.
* @throws ClassCastException input of instance of CodaPhaseDescriptorTN
*/
    public void changeDescriptor(CodaPhaseDescriptor cd) {
        if (! cd.equals(this.descriptor)) {
            this.descriptor  = (CodaPhaseDescriptorTN) cd;
            update = true;
        }
    }

/**
* Action taken will depend on the initialization status of the coda (fromDbase == true).
* This state controls whether DataSource data is created, deleted, modified, or unchanged.
* To enable writing to the DataSource, DataSource.setWriteBackEnabled(true) must be invoked BEFORE data is read.
* Because deleting a Coda table row in the database would possibly invalidate an existing
* coda associations, this implementation writes new AssocCoO and AssocCoM table rows
* to preserve changes to the Coda data.
* @see DataSource#setWriteBackEnabled(boolean)
* @see DataSource#isWriteBackEnabled()
*/
    public boolean commit() {

        if (! DataSource.isWriteBackEnabled()) {
            System.out.println("CodaTN commit error DataSource.isWriteBackEnabled==false " +
               getChannelObj().getChannelId().toString());
            return false;
        }

        if (debug) System.out.println ("CodaTN.commit() : fromDB = "+ fromDbase+ "  isDeleted()= "+isDeleted());

        if (isDeleted() ) return true;

        if (isAssociated() ) {
            if ( ((SolutionTN)sol).getOrid() == 0) {
                System.out.println ("CodaTN associated Solution has no orid sol: " + sol.id.toString() +
                                    " " + getChannelObj().getChannelId().toString());
                return false;
            }
        }
        else if (joinType == Type_AssocCoO || joinType == Type_Assoc) return true;

        if (isAssociatedWithMag() &&  magnitude.magid.isNull()) {  // like Solution, needs getMagid()? AWW
            System.out.println ("CodaTN associated Magnitude has no magid: " + getChannelObj().getChannelId().toString());
            return false;
        }

        if (fromDbase) {
            if (hasChanged()) {
                if (debug) System.out.println ("(changed coda) INSERT and assoc");
                boolean status = dbaseInsert();
                if (status) update = false; // reset the change flag
                return status;
            } else {
                if (debug) System.out.println ("(coda unchanged) assoc only");
                return dbaseAssociate();
            }
        } else {
            if (debug) System.out.println ("(new coda) INSERT and assoc");
            return dbaseInsert();
        }
    }

/**
* Does a no-op, returns true, no existing codas are deleted.
*/
    protected boolean dbaseDelete () {
            return true;
    }

/**
* Makes a new AssocCoO table row if isAssociated() == true.
* then makes a new AssocCoM table row if isAssociatedWithMag() == true.
* Returns true upon successfully creating new association row(s).
* Returns false if isAssociated() == false or an error occurs creating any association row.
* @see #isAssociated()
* @see #isAssociatedWithMag()
* @see #dbaseAssociateOrigin()
* @see #dbaseAssociateMag()
*/
    protected boolean dbaseAssociate() {
        // must have a valid origin association
        if ( isAssociated()) {
            if ( ! dbaseAssociateOrigin()) return false;  // abort here
        }
        else return false; // abort here, associated solution is required by-pass magnitude association

        return (isAssociatedWithMag()) ? dbaseAssociateMag() : true; // return true, associated mag not required
    }

/**
* Makes a new AssocCoO table row for this Coda, if isAssociated() == true.
* Returns true upon successfully creating new association row.
* Returns false if no association exists or an error occurs creating association row.
* @see #isAssociated()
* @see #dbaseAssociate()
*/
    protected boolean dbaseAssociateOrigin() {
        if ( ! isAssociated() ) return false;
        AssocCoO assocRow = toAssocCoORow();
        if (assocRow == null) return false;
        assocRow.setProcessing(DataTableRowStates.INSERT);
        return (assocRow.insertRow(DataSource.getConnection()) > 0);
    }

/**
* Makes a new AssocCoM table row for this Coda, if isAssociatedWithMag() == true.
* Returns true upon successfully creating new association row.
* Returns false if no association exists or an error occurs creating association row.
* @see #isAssociatedWithMag()
* @see #dbaseAssociate()
*/
    public boolean commitAssocMag() {
         return dbaseAssociateMag();
    }

    protected boolean dbaseAssociateMag() {
        if ( ! isAssociatedWithMag() ) return false;
        AssocCoM assocRow = toAssocCoMRow();
        if (assocRow == null) return false;
        assocRow.setProcessing(DataTableRowStates.INSERT);
        return (assocRow.insertRow(DataSource.getConnection()) > 0);
    }

/**
* Inserts a Coda row and any associated AssocCoO and/or AssocCoM table rows(s) into the DataSource database.
* Returns true upon success. Returns false if isAssociated() == false or an error occurs attempting to create
* any of these new rows.
*/
    protected boolean dbaseInsert () {
        if (debug) System.out.println ("dbaseInsert: "+ this.toString());
        boolean status = true;

        org.trinet.jdbc.table.Coda codaRow = toCodaRow();
        codaRow.setProcessing(DataTableRowStates.INSERT);
        status = (codaRow.insertRow(DataSource.getConnection()) > 0);

        if (status) {
            setUpdate(true);
            status = dbaseAssociate();
        }
        return status;
    }

/**
* Returns the value of the coda id number, corresponding to 'coid' of the table row, if initialized from the database.
* If identifier is  not initialized, 0 is returned.
* @see #getBySolution(long)
* @see #getBySolution(Solution)
* @see #getByMagnitude(long)
* @see #getByMagnitude(Magnitude)
*/
    public long getCoid() {
        return (coid.isNull()) ? 0 : coid.longValue();
    }

/**
* Returns true if this instance was not initialized from the database data.
* Otherwise returns true if isUpdate() == true or hasChangedAttributes() == true.
*/
    protected boolean hasChanged() {

⌨️ 快捷键说明

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