/*
 * MATLAB Compiler: 4.18 (R2012b)
 * Date: Sat Apr 25 10:48:32 2015
 * Arguments: "-B" "macro_default" "-W" "java:KalmanFilterJava,KalmanFilterJava" "-T" 
 * "link:lib" "-d" "C:\\Users\\Administrator\\Desktop\\Oil Gas Data 
 * 2\\Identification\\KalmanFilterJava\\src" "-w" "enable:specified_file_mismatch" "-w" 
 * "enable:repeated_file" "-w" "enable:switch_ignored" "-w" "enable:missing_lib_sentinel" 
 * "-w" "enable:demo_license" "-v" 
 * "class{KalmanFilterJava:C:\\Users\\Administrator\\Desktop\\Oil Gas Data 
 * 2\\Identification\\KalmanFilterJava.m}" 
 */

package KalmanFilterJava;

import com.mathworks.toolbox.javabuilder.*;
import com.mathworks.toolbox.javabuilder.internal.*;
import java.util.*;

/**
 * The <code>KalmanFilterJava</code> class provides a Java interface to the M-functions
 * from the files:
 * <pre>
 *  C:\\Users\\Administrator\\Desktop\\Oil Gas Data 2\\Identification\\KalmanFilterJava.m
 * </pre>
 * The {@link #dispose} method <b>must</b> be called on a <code>KalmanFilterJava</code> 
 * instance when it is no longer needed to ensure that native resources allocated by this 
 * class are properly freed.
 * @version 0.0
 */
public class KalmanFilterJava extends MWComponentInstance<KalmanFilterJava>
{
    /**
     * Tracks all instances of this class to ensure their dispose method is
     * called on shutdown.
     */
    private static final Set<Disposable> sInstances = new HashSet<Disposable>();

    /**
     * Maintains information used in calling the <code>KalmanFilterJava</code> M-function.
     */
    private static final MWFunctionSignature sKalmanFilterJavaSignature =
        new MWFunctionSignature(/* max outputs = */ 1,
                                /* has varargout = */ false,
                                /* function name = */ "KalmanFilterJava",
                                /* max inputs = */ 2,
                                /* has varargin = */ false);

    /**
     * Shared initialization implementation - private
     */
    private KalmanFilterJava (final MWMCR mcr) throws MWException
    {
        super(mcr);
        // add this to sInstances
        synchronized(KalmanFilterJava.class) {
            sInstances.add(this);
        }
    }

    /**
     * Constructs a new instance of the <code>KalmanFilterJava</code> class.
     */
    public KalmanFilterJava() throws MWException
    {
        this(KalmanFilterJavaMCRFactory.newInstance());
    }
    
    private static MWComponentOptions getPathToComponentOptions(String path)
    {
        MWComponentOptions options = new MWComponentOptions(new MWCtfExtractLocation(path),
                                                            new MWCtfDirectorySource(path));
        return options;
    }
    
    /**
     * @deprecated Please use the constructor {@link #KalmanFilterJava(MWComponentOptions componentOptions)}.
     * The <code>com.mathworks.toolbox.javabuilder.MWComponentOptions</code> class provides API to set the
     * path to the component.
     * @param pathToComponent Path to component directory.
     */
    public KalmanFilterJava(String pathToComponent) throws MWException
    {
        this(KalmanFilterJavaMCRFactory.newInstance(getPathToComponentOptions(pathToComponent)));
    }
    
    /**
     * Constructs a new instance of the <code>KalmanFilterJava</code> class. Use this 
     * constructor to specify the options required to instantiate this component.  The 
     * options will be specific to the instance of this component being created.
     * @param componentOptions Options specific to the component.
     */
    public KalmanFilterJava(MWComponentOptions componentOptions) throws MWException
    {
        this(KalmanFilterJavaMCRFactory.newInstance(componentOptions));
    }
    
    /** Frees native resources associated with this object */
    public void dispose()
    {
        try {
            super.dispose();
        } finally {
            synchronized(KalmanFilterJava.class) {
                sInstances.remove(this);
            }
        }
    }
  
    /**
     * Invokes the first m-function specified by MCC, with any arguments given on
     * the command line, and prints the result.
     */
    public static void main (String[] args)
    {
        try {
            MWMCR mcr = KalmanFilterJavaMCRFactory.newInstance();
            mcr.runMain( sKalmanFilterJavaSignature, args);
            mcr.dispose();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    
    /**
     * Calls dispose method for each outstanding instance of this class.
     */
    public static void disposeAllInstances()
    {
        synchronized(KalmanFilterJava.class) {
            for (Disposable i : sInstances) i.dispose();
            sInstances.clear();
        }
    }

    /**
     * Provides the interface for calling the <code>KalmanFilterJava</code> M-function 
     * where the first input, an instance of List, receives the output of the M-function and
     * the second input, also an instance of List, provides the input to the M-function.
     * <p>M-documentation as provided by the author of the M function:
     * <pre>
     * % Assume that the process noise covariance matrix V is also initially equal
     * % to process covariance matrix
     * </pre>
     * </p>
     * @param lhs List in which to return outputs. Number of outputs (nargout) is
     * determined by allocated size of this List. Outputs are returned as
     * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>.
     * Each output array should be freed by calling its <code>dispose()</code>
     * method.
     *
     * @param rhs List containing inputs. Number of inputs (nargin) is determined
     * by the allocated size of this List. Input arguments may be passed as
     * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or
     * as arrays of any supported Java type. Arguments passed as Java types are
     * converted to MATLAB arrays according to default conversion rules.
     * @throws MWException An error has occurred during the function call.
     */
    public void KalmanFilterJava(List lhs, List rhs) throws MWException
    {
        fMCR.invoke(lhs, rhs, sKalmanFilterJavaSignature);
    }

    /**
     * Provides the interface for calling the <code>KalmanFilterJava</code> M-function 
     * where the first input, an Object array, receives the output of the M-function and
     * the second input, also an Object array, provides the input to the M-function.
     * <p>M-documentation as provided by the author of the M function:
     * <pre>
     * % Assume that the process noise covariance matrix V is also initially equal
     * % to process covariance matrix
     * </pre>
     * </p>
     * @param lhs array in which to return outputs. Number of outputs (nargout)
     * is determined by allocated size of this array. Outputs are returned as
     * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>.
     * Each output array should be freed by calling its <code>dispose()</code>
     * method.
     *
     * @param rhs array containing inputs. Number of inputs (nargin) is
     * determined by the allocated size of this array. Input arguments may be
     * passed as sub-classes of
     * <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or as arrays of
     * any supported Java type. Arguments passed as Java types are converted to
     * MATLAB arrays according to default conversion rules.
     * @throws MWException An error has occurred during the function call.
     */
    public void KalmanFilterJava(Object[] lhs, Object[] rhs) throws MWException
    {
        fMCR.invoke(Arrays.asList(lhs), Arrays.asList(rhs), sKalmanFilterJavaSignature);
    }

    /**
     * Provides the standard interface for calling the <code>KalmanFilterJava</code>
     * M-function with 2 input arguments.
     * Input arguments may be passed as sub-classes of
     * <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or as arrays of
     * any supported Java type. Arguments passed as Java types are converted to
     * MATLAB arrays according to default conversion rules.
     *
     * <p>M-documentation as provided by the author of the M function:
     * <pre>
     * % Assume that the process noise covariance matrix V is also initially equal
     * % to process covariance matrix
     * </pre>
     * </p>
     * @param nargout Number of outputs to return.
     * @param rhs The inputs to the M function.
     * @return Array of length nargout containing the function outputs. Outputs
     * are returned as sub-classes of
     * <code>com.mathworks.toolbox.javabuilder.MWArray</code>. Each output array
     * should be freed by calling its <code>dispose()</code> method.
     * @throws MWException An error has occurred during the function call.
     */
    public Object[] KalmanFilterJava(int nargout, Object... rhs) throws MWException
    {
        Object[] lhs = new Object[nargout];
        fMCR.invoke(Arrays.asList(lhs), 
                    MWMCR.getRhsCompat(rhs, sKalmanFilterJavaSignature), 
                    sKalmanFilterJavaSignature);
        return lhs;
    }
}
