view swig/java/test.java @ 214:f28f66faa016

Add "stateful" feature type with initial feature "last n" Stateful feature extraction functions are functions that require state to be maintained between successive calls. This is necessary, for example when an accumulation of values is required, or changes need to be measured over time. The initial xtract_last_n() function accumulates the last N (single) values from *data and writes them to *result
author Jamie Bullock <jamie@jamiebullock.com>
date Tue, 03 Jun 2014 21:17:07 +0100
parents 826eb46b2f91
children
line wrap: on
line source

import xtract.core.*;
import java.util.Arrays;

public class test {
    public static void main(String argv[]) {

        try {
            System.loadLibrary("jxtract");
        }
        catch (UnsatisfiedLinkError e) {
            System.out.println("Failed to load the library \"jxtract\"");
            System.out.println(e.toString());
            System.exit(0);
        }

        System.out.println("\nRunning libxtract Java bindings test...\n");

        int len          = 5;
        int retval       = 0;
        double mean[]     = new double[1];
        double variance[] = new double[1];
        double data[]     = new double[len];

        for (int i = 0; i < len; i++){
            System.out.print(i * 3 + ", ");
            data[i] = i * 3;
        }

        retval = xtract.xtract_mean(data, len, null, mean);
        retval = xtract.xtract_variance(data, len, mean, variance);

        System.out.print("The mean of: " + Arrays.toString(data) + " is "
                + mean[0] + "\nThe variance is: " + variance[0] + "\n");
    }
}