SCITest.java [src/java/m/sci] Revision: 7f16de24efff2958d5552d684892a367a9f8ef3d  Date: Tue Mar 29 13:19:23 MDT 2016
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package m.sci;

// THIS CODE COULD BE OF USE AS AN SCI REFERENCE
// OR DELETED
// WJL 3/29/2016
/**
 *
 * @author od
 * @author jplyon
 */
public class SCITest {
    
    /**
     * The reference erosion rate at the Renner, TX research location.
     * This is an erosion rate at which organic matter was constant.
     */
    public static final double ER_Renner = 2.54; // [ton/acre/year]
    
    public class SciFactors {
//        double      ER;       // Erosion Rate [ton/acre/year]
//                              // RUSLE2 parameter SLOPE_DEGRAD.
//                              // WEPS parameter WindEros in "sci_energy.out" [kilogram/meter^2/year]
        double      SCI;        // SCI total value [-]
                                // RUSLE2 parameter SOIL_COND_INDEX_RESULT
                                // WEPS parameter Soil_conditioning_index in "sci_energy.out"
        double      SCI_ER;     // SCI ER (Erosion Rate) subfactor [-]
                                // RUSLE2 parameter SOIL_COND_INDEX_ER_SUBFACTOR
                                // WEPS parameter sci_er_factor in "sci_energy.out"
        double      SCI_FO;     // SCI FO (Field Operations) subfactor [-]
                                // RUSLE2 parameter SOIL_COND_INDEX_FO_SUBFACTOR
                                // WEPS parameter sci_fo_factor in "sci_energy.out"
        double      SCI_OM;     // SCI OM (Organic Matter) subfactor [-]
                                // RUSLE2 parameter SOIL_COND_INDEX_OM_SUBFACTOR
                                // WEPS parameter sci_om_factor in "sci_energy.out"

        /** Constructor - note parameters are in alphabetical order.
         * 
         * @param SCI
         * @param SCI_ER
         * @param SCI_FO
         * @param SCI_OM 
         */
        public SciFactors(double SCI, double SCI_ER, double SCI_FO, double SCI_OM) {
            this.SCI    = SCI;
            this.SCI_ER = SCI_ER;
            this.SCI_FO = SCI_FO;
            this.SCI_OM = SCI_OM;
        }
    }
    
    /**
     * Calculate SCI
     * @param SCI_Water  SCI factors computed by RUSLE.
     * @param SCI_Wind   SCI factors computed by WEPS.
     * @param ER_Extra   Soil loss from causes other than wind and water erosion.
     *                   This includes subsidence of histosols.
     *                   Units of [ton/acre/year].
     * @return The composite SCI values computed using the SCI of the dominant process
     *   and the erosion rate of the other process.
     * @note This function is currently symmetric in its arguments.
     */
    public SciFactors CalcSci(SciFactors SCI_Water, SciFactors SCI_Wind, double ER_Extra) {
        SciFactors SCI;
        if (SCI_Water == null) {
            SCI = SCI_Wind;
        } else if (SCI_Wind == null) {
            SCI = SCI_Water;
        } // Both are computed and wind erosion is dominant.
        else if (SCI_Wind.SCI_ER > SCI_Water.SCI_ER) {
            double new_SCI_ER = SCI_Water.SCI_ER + SCI_Wind.SCI_ER - 1.0 - (ER_Extra / ER_Renner);
            double new_SCI_FO = SCI_Wind.SCI_FO;            // @note SCI_FO should be the same for both models.
            double new_SCI_OM = SCI_Wind.SCI_OM;
            double new_SCI = 0.4 * new_SCI_OM + 0.4 * new_SCI_FO + 0.2 * new_SCI_ER;

            SCI = new SciFactors(new_SCI, new_SCI_ER, new_SCI_FO, new_SCI_OM);
        } // Both are computed and water erosin is dominant.
        else {
            double new_SCI_ER = SCI_Water.SCI_ER + SCI_Wind.SCI_ER - 1.0 - (ER_Extra / ER_Renner);
            double new_SCI_FO = SCI_Water.SCI_FO;            // @note SCI_FO should be the same for both models.
            double new_SCI_OM = SCI_Water.SCI_OM;
            double new_SCI = 0.4 * new_SCI_OM + 0.4 * new_SCI_FO + 0.2 * new_SCI_ER;

            SCI = new SciFactors(new_SCI, new_SCI_ER, new_SCI_FO, new_SCI_OM);
        }

        return SCI;
    }

    /**
     * @note This function has the same arguments as CalcSci().
     * @param SCI_Water
     * @param SCI_Wind
     * @param ER_Extra 
     */
    public void PrintSci(SciFactors SCI_Water, SciFactors SCI_Wind, double ER_Extra) {
        SciFactors SCI_Total = CalcSci(SCI_Water, SCI_Wind, ER_Extra);
        if (SCI_Water != null)
            System.out.println("Model 1 inputs (SCI=" + SCI_Water.SCI  + ", SCI_ER=" + SCI_Water.SCI_ER
                                    + ", SCI_FO=" + SCI_Water.SCI_FO  + ", SCI_OM=" + SCI_Water.SCI_OM + ")" );
        if (SCI_Wind != null)
            System.out.println("Model 2 inputs (SCI=" + SCI_Wind.SCI  + ", SCI_ER=" + SCI_Wind.SCI_ER
                                    + ", SCI_FO=" + SCI_Wind.SCI_FO  + ", SCI_OM=" + SCI_Wind.SCI_OM + ")" );
        if (ER_Extra > 0.0)
            System.out.println("ER_Extra=" + ER_Extra + ")" );
        //
        System.out.println("SCI outputs (SCI=" + SCI_Total.SCI  + ", SCI_ER=" + SCI_Total.SCI_ER
                                + ", SCI_FO=" + SCI_Total.SCI_FO  + ", SCI_OM=" + SCI_Total.SCI_OM + ")" );
        System.out.println("");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SCITest stub = new SCITest();
        stub.Test();
    }
    
    public void Test() {
        // Warning - these values may not be consistent.
        PrintSci( new SciFactors(/*17,*/     -3.5695, -17.333, 0.74257, -1.0),      // Water
                  new SciFactors(/*0.0124,*/  0.171,   0.9782, 0.3195,  -0.3817),   // Wind
                  0.0);                                                             // Extra
        PrintSci( new SciFactors(/*17,*/ -3.5695, -17.333, 0.74257, -1.0),          // Water
                  null,                                                             // Wind
                  0.0);                                                             // Extra
        PrintSci( null,                                                             // Water
                  new SciFactors(/*0.0124,*/  0.171,   0.9782, 0.3195,  -0.3817),   // Wind
                  0.0);                                                             // Extra
    }
}