Search in sources :

Example 1 with EventStep

use of gov.sandia.n2a.backend.internal.EventStep in project n2a by frothga.

the class Input method getRow.

public Holder getRow(Instance context, Type op1, boolean time) {
    Simulator simulator = Simulator.getSimulator(context);
    // If we can't cache a line from the requested stream, then semantics of this function are lost, so give up.
    if (simulator == null)
        return null;
    Holder H = null;
    try {
        // get an input holder
        String path = ((Text) operands[0].eval(context)).value;
        H = simulator.inputs.get(path);
        if (H == null) {
            H = new Holder();
            if (// not ideal; reading stdin should be reserved for headless operation
            path.isEmpty())
                // not ideal; reading stdin should be reserved for headless operation
                H.stream = new BufferedReader(new InputStreamReader(System.in));
            else
                H.stream = new BufferedReader(new FileReader(new File(path).getAbsoluteFile()));
            // sqrt (epsilon for time representation (currently double)), about 1e-8
            H.epsilon = Math.sqrt(Math.ulp(1.0));
            if (simulator.currentEvent instanceof EventStep)
                H.epsilon = Math.min(H.epsilon, ((EventStep) simulator.currentEvent).dt / 1000);
            simulator.inputs.put(path, H);
        }
        if (op1 instanceof Scalar)
            H.getRow(((Scalar) op1).value, time);
        else
            H.getRow(0, time);
    } catch (IOException e) {
        return null;
    }
    return H;
}
Also used : InputStreamReader(java.io.InputStreamReader) EventStep(gov.sandia.n2a.backend.internal.EventStep) BufferedReader(java.io.BufferedReader) Text(gov.sandia.n2a.language.type.Text) FileReader(java.io.FileReader) IOException(java.io.IOException) Simulator(gov.sandia.n2a.backend.internal.Simulator) File(java.io.File) Scalar(gov.sandia.n2a.language.type.Scalar)

Aggregations

EventStep (gov.sandia.n2a.backend.internal.EventStep)1 Simulator (gov.sandia.n2a.backend.internal.Simulator)1 Scalar (gov.sandia.n2a.language.type.Scalar)1 Text (gov.sandia.n2a.language.type.Text)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1