// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double[] a_div(double[] x, double[] y) {
//     Assert.argument(x.length == y.length);
//     double[] z = new double[x.length];
//     for (int i = 0; i < x.length; i++) {
//         z[i] = x[i] / y[i];
//     }
//     return z;
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double[] a_exp(double[] x) {
//     return DoubleStream.of(x).map(Math::exp).toArray();
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double a_max(double[] x) {
//     double max = Double.NEGATIVE_INFINITY;
//     for (double v : x) {
//         max = Math.max(max, v);
//     }
//     return max;
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double a_min(double[] x) {
//     double min = Double.POSITIVE_INFINITY;
//     for (double v : x) {
//         min = Math.min(min, v);
//     }
//     return min;
// }


import org.esa.snap.core.gpf.OperatorException;
import org.esa.snap.core.nn.NNffbpAlphaTabFast;
import org.esa.snap.core.util.BitSetter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.log;
import static java.lang.Math.sin;
import static java.lang.Math.toDegrees;
import static java.lang.Math.toRadians;
import static org.esa.s3tbx.ArrayMath.a_div;
import static org.esa.s3tbx.ArrayMath.a_exp;
import static org.esa.s3tbx.ArrayMath.a_max;
import static org.esa.s3tbx.ArrayMath.a_min;
        return new Result(rw, iops_nn1, r_tosa, rtosa_aann, rtosa_aaNNrat_min, rtosa_aaNNrat_max, flags);
    }

    C2rccSeaWiFSAlgorithm() throws IOException {
        aaNN_test_oos_rtosa = nnhs("seawifs/coastcolour_atmo_press_20150221/rtoa_seaw_aaNN7/31x7x31_215.9.net");
        rtosa_rw_nn = nnhs("seawifs/coastcolour_atmo_press_20150221/rtoa_rw_seaw_nn3/33x73x53x33_515179.0.net");
        logrw_iop_NN = nnhs("seawifs/coastcolour_wat_20140318/inv_seawifs_logrw_logiop_20140318_noise_p5/87x77x37_14386.6.net");
    }

    private ThreadLocal<NNffbpAlphaTabFast> nnhs(String path) throws IOException {
        String name = "/auxdata/nets/" + path;
        InputStream stream = C2rccSeaWiFSAlgorithm.class.getResourceAsStream(name);
        if (stream == null) {
            throw new IllegalStateException("resource not found: " + name);
        }
        final String nnCode = readFully(stream);
        return new ThreadLocal<NNffbpAlphaTabFast>() {
            @Override
            protected NNffbpAlphaTabFast initialValue() {
                try {
                    return new NNffbpAlphaTabFast(nnCode);
                } catch (IOException e) {
                    throw new IllegalStateException(e);
                }
            }
        };
    }

    private String readFully(InputStream stream) throws IOException {
        String text;
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double[] a_div(double[] x, double[] y) {
//     Assert.argument(x.length == y.length);
//     double[] z = new double[x.length];
//     for (int i = 0; i < x.length; i++) {
//         z[i] = x[i] / y[i];
//     }
//     return z;
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double[] a_exp(double[] x) {
//     return DoubleStream.of(x).map(Math::exp).toArray();
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double a_max(double[] x) {
//     double max = Double.NEGATIVE_INFINITY;
//     for (double v : x) {
//         max = Math.max(max, v);
//     }
//     return max;
// }
// 
// Path: src/main/java/org/esa/s3tbx/ArrayMath.java
// public static double a_min(double[] x) {
//     double min = Double.POSITIVE_INFINITY;
//     for (double v : x) {
//         min = Math.min(min, v);
//     }
//     return min;
// }


// Path: src/main/java/org/esa/s3tbx/c2rcc/seawifs/C2rccSeaWiFSAlgorithm.java
import org.esa.snap.core.gpf.OperatorException;
import org.esa.snap.core.nn.NNffbpAlphaTabFast;
import org.esa.snap.core.util.BitSetter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.log;
import static java.lang.Math.sin;
import static java.lang.Math.toDegrees;
import static java.lang.Math.toRadians;
import static org.esa.s3tbx.ArrayMath.a_div;
import static org.esa.s3tbx.ArrayMath.a_exp;
import static org.esa.s3tbx.ArrayMath.a_max;
import static org.esa.s3tbx.ArrayMath.a_min;

        return new Result(rw, iops_nn1, r_tosa, rtosa_aann, rtosa_aaNNrat_min, rtosa_aaNNrat_max, flags);
    }

    C2rccSeaWiFSAlgorithm() throws IOException {
        aaNN_test_oos_rtosa = nnhs("seawifs/coastcolour_atmo_press_20150221/rtoa_seaw_aaNN7/31x7x31_215.9.net");
        rtosa_rw_nn = nnhs("seawifs/coastcolour_atmo_press_20150221/rtoa_rw_seaw_nn3/33x73x53x33_515179.0.net");
        logrw_iop_NN = nnhs("seawifs/coastcolour_wat_20140318/inv_seawifs_logrw_logiop_20140318_noise_p5/87x77x37_14386.6.net");
    }

    private ThreadLocal<NNffbpAlphaTabFast> nnhs(String path) throws IOException {
        String name = "/auxdata/nets/" + path;
        InputStream stream = C2rccSeaWiFSAlgorithm.class.getResourceAsStream(name);
        if (stream == null) {
            throw new IllegalStateException("resource not found: " + name);
        }
        final String nnCode = readFully(stream);
        return new ThreadLocal<NNffbpAlphaTabFast>() {
            @Override
            protected NNffbpAlphaTabFast initialValue() {
                try {
                    return new NNffbpAlphaTabFast(nnCode);
                } catch (IOException e) {
                    throw new IllegalStateException(e);
                }
            }
        };
    }

    private String readFully(InputStream stream) throws IOException {
        String text;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {