import GrapherGUI.*;

import java.awt.Color;


public class Native extends Function {

    public short type() {
        return Function.FCNTYPE_ARRAY;
    }

    // we aren't using this one but it needs to
    // be declared
    public double f(double in, SliderMatrix p) {
        return 0.0;
    }

    public void farray(
            double minx,
            double maxx,
            int density,
            double[] varIndep,  // results will be stored in here
            double[] varDep,    // results will be stored in here
            SliderMatrix p) {

        double t, h, sigma;

        try {
            t = p.val("t");
            h = p.val("h");
            sigma = p.val("sigma");
        } catch (Error e) {
            // this would be, under any normal circumstances,
            // a fatal error;
            // we should be exiting... but this is just a test
            System.out.println("FATAL ERROR: could not retrieve parameter(s)");
            return;
        }

        double dx, x;

        dx = Math.abs(maxx - minx) / (double) density;
        for (int i = 0; i < density; i++) {
            varIndep[i] = minx + ((double) i) * dx;
        }

        // System.out.println("Before _ncf_interface() call");
        _ncf_interface(minx, maxx, density, varIndep, varDep, t, h, sigma);
    }

    public Color color() {
        return Color.black;
    }

    public String name() {
        return "Native Fortran Function";
    }

    // (n)ative (c) to (f)ortran interface function
    private native void _ncf_interface(
            double minx,
            double maxx,
            int density,
            double[] varIndep,
            double[] varDep,
            double t, double g, double sigma);

    static {
        System.loadLibrary("Native");
    }
}