Search in sources :

Example 36 with Array

use of com.beanit.openiec61850.Array in project open-smart-grid-platform by OSGP.

the class NodeContainer method writeDateArray.

public void writeDateArray(final SubDataAttribute child, final Date[] values) throws NodeWriteException {
    final Array array = (Array) this.parent.getChild(child.getDescription());
    if (array.size() != values.length) {
        throw new NodeWriteException(String.format("Invalid array size %d. Size on device is %d", values.length, array.size()));
    }
    for (int i = 0; i < values.length; i++) {
        final BdaTimestamp bdaTimestamp = (BdaTimestamp) array.getChild(i);
        bdaTimestamp.setDate(values[i]);
    }
    this.writeNode(array);
}
Also used : Array(com.beanit.openiec61850.Array) NodeWriteException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException) BdaTimestamp(com.beanit.openiec61850.BdaTimestamp)

Example 37 with Array

use of com.beanit.openiec61850.Array in project open-smart-grid-platform by OSGP.

the class NodeContainer method getFloatArray.

public Float[] getFloatArray(final SubDataAttribute child) {
    final Array array = (Array) this.parent.getChild(child.getDescription());
    final int size = array.size();
    final Float[] result = new Float[size];
    for (int i = 0; i < size; i++) {
        result[i] = ((BdaFloat32) array.getChild(i)).getFloat();
    }
    return result;
}
Also used : Array(com.beanit.openiec61850.Array)

Example 38 with Array

use of com.beanit.openiec61850.Array in project open-smart-grid-platform by OSGP.

the class LightMeasurementRtu method setGeneralIO.

/**
 * Updates the value for the status of the 4 light sensors.
 *
 * @param bdaValue Array indicating which the status per light sensor. Each element in the array
 *     represents the status for one light sensor. Meaning of an element: 0 = OFF, greater than 0
 *     = ON. When there are less than 4 elements, the remaining light sensors will be set to OFF.
 * @return The updated values.
 */
private List<BasicDataAttribute> setGeneralIO(final byte[] bdaValue) {
    final List<BasicDataAttribute> values = new ArrayList<>();
    for (short lmIndex = 1; lmIndex <= 4; lmIndex++) {
        boolean stVal = false;
        if (bdaValue != null && bdaValue.length >= lmIndex) {
            stVal = bdaValue[lmIndex - 1] - 48 > 0;
        }
        final BasicDataAttribute bda = this.setBoolean(LogicalDeviceNode.fromDescription("SPGGIO" + lmIndex + ".Ind.stVal"), stVal);
        values.add(bda);
    }
    return values;
}
Also used : ArrayList(java.util.ArrayList) BasicDataAttribute(com.beanit.openiec61850.BasicDataAttribute)

Example 39 with Array

use of com.beanit.openiec61850.Array in project risky by amsa-code.

the class NetcdfFixesWriter method writeFixes.

public static void writeFixes(List<HasFix> fixes, File file) {
    if (fixes.size() == 0) {
        return;
    }
    try {
        // TODO evaluate use of NetCdf structures
        NetcdfFileWriter f = NetcdfFileWriter.createNew(Version.netcdf3, file.getPath());
        // add version attribute
        f.addGroupAttribute(null, new Attribute("version", "0.1"));
        // Create netCDF dimensions
        Dimension dimTime = f.addUnlimitedDimension("time");
        Dimension dimLat = f.addDimension(null, "latitude", fixes.size());
        Dimension dimLon = f.addDimension(null, "longitude", fixes.size());
        Dimension dimSource = f.addDimension(null, "source", fixes.size());
        Dimension dimLatency = f.addDimension(null, "latency", fixes.size());
        Dimension dimNavStatus = f.addDimension(null, "navigational_status", fixes.size());
        Dimension dimRateOfTurn = f.addDimension(null, "rate_of_turn", fixes.size());
        Dimension dimSpeedOverGround = f.addDimension(null, "speed_over_ground", fixes.size());
        Dimension dimCourseOverGround = f.addDimension(null, "course_over_ground", fixes.size());
        Dimension dimHeading = f.addDimension(null, "heading", fixes.size());
        Dimension dimAisClass = f.addDimension(null, "ais_class", fixes.size());
        Variable varLat = f.addVariable(null, "latitude", DataType.FLOAT, Arrays.asList(dimLat));
        varLat.addAttribute(new Attribute("units", "degrees_east"));
        varLat.addAttribute(new Attribute("standard_name", "latitude"));
        varLat.addAttribute(new Attribute("long_name", "latitude of craft position"));
        Variable varLon = f.addVariable(null, "longitude", DataType.FLOAT, Arrays.asList(dimLon));
        varLon.addAttribute(new Attribute("units", "degrees_north"));
        varLon.addAttribute(new Attribute("standard_name", "longitude"));
        varLon.addAttribute(new Attribute("long_name", "longitude of craft position"));
        Variable varTime = f.addVariable(null, "time", DataType.DOUBLE, Arrays.asList(dimTime));
        varTime.addAttribute(new Attribute("units", "days since 1970-01-01 00:00:00 UTC"));
        Variable varSource = f.addVariable(null, "source", DataType.SHORT, Arrays.asList(dimSource));
        varSource.addAttribute(new Attribute("encoding", "0=not present, 1=present, others TBA"));
        Variable varLatency = f.addVariable(null, "latency", DataType.INT, Arrays.asList(dimLatency));
        varLatency.addAttribute(new Attribute("units", "s"));
        varLatency.addAttribute(new Attribute("encoding", "-1=not present"));
        Variable varNavStatus = f.addVariable(null, "navigational_status", DataType.BYTE, Arrays.asList(dimNavStatus));
        varNavStatus.addAttribute(new Attribute("encoding", "127=not present"));
        Variable varRateOfTurn = f.addVariable(null, "rate_of_turn", DataType.BYTE, Arrays.asList(dimRateOfTurn));
        varRateOfTurn.addAttribute(new Attribute("encoding", "-128=not present, others TBA"));
        Variable varSpeedOverGround = f.addVariable(null, "speed_over_ground", DataType.SHORT, Arrays.asList(dimSpeedOverGround));
        varSpeedOverGround.addAttribute(new Attribute("units", "1/10 knot"));
        varSpeedOverGround.addAttribute(new Attribute("encoding", "1023=not present"));
        Variable varCourseOverGround = f.addVariable(null, "course_over_ground", DataType.SHORT, Arrays.asList(dimCourseOverGround));
        varCourseOverGround.addAttribute(new Attribute("units", "1/10 degree"));
        varCourseOverGround.addAttribute(new Attribute("encoding", "3600=not present"));
        Variable varHeading = f.addVariable(null, "heading", DataType.SHORT, Arrays.asList(dimHeading));
        varHeading.addAttribute(new Attribute("units", "degrees"));
        varHeading.addAttribute(new Attribute("encoding", "360=not present"));
        Variable varAisClass = f.addVariable(null, "ais_class", DataType.BYTE, Arrays.asList(dimAisClass));
        varAisClass.addAttribute(new Attribute("encoding", "0=A,1=B"));
        // create the file
        f.create();
        int[] shape = new int[] { fixes.size() };
        Array dataLat = Array.factory(DataType.FLOAT, shape);
        Array dataLon = Array.factory(DataType.FLOAT, shape);
        Array dataTime = Array.factory(DataType.DOUBLE, shape);
        Array dataSource = Array.factory(DataType.SHORT, shape);
        Array dataLatency = Array.factory(DataType.INT, shape);
        Array dataNavStatus = Array.factory(DataType.BYTE, shape);
        Array dataRateOfTurn = Array.factory(DataType.BYTE, shape);
        Array dataSpeedOverGround = Array.factory(DataType.SHORT, shape);
        Array dataCourseOverGround = Array.factory(DataType.SHORT, shape);
        Array dataHeading = Array.factory(DataType.SHORT, shape);
        Array dataAisClass = Array.factory(DataType.BYTE, shape);
        for (int i = 0; i < fixes.size(); i++) {
            Fix fix = fixes.get(i).fix();
            // latitude
            dataLat.setFloat(i, fix.lat());
            // longitude
            dataLon.setFloat(i, fix.lon());
            // time
            double days = (double) fix.time() / TimeUnit.DAYS.toMillis(1);
            dataTime.setDouble(i, days);
            // source
            dataSource.setShort(i, fix.source().orElse(BinaryFixes.SOURCE_ABSENT));
            // latency
            dataLatency.setInt(i, fix.latencySeconds().orElse(BinaryFixes.LATENCY_ABSENT));
            // navigational status
            int navStatus;
            if (fix.navigationalStatus().isPresent())
                navStatus = fix.navigationalStatus().get().ordinal();
            else
                navStatus = BinaryFixes.NAV_STATUS_ABSENT;
            dataNavStatus.setByte(i, (byte) navStatus);
            // rate of turn
            dataRateOfTurn.setByte(i, BinaryFixes.RATE_OF_TURN_ABSENT);
            // SOG
            final short sog;
            if (fix.speedOverGroundKnots().isPresent())
                sog = (short) Math.round(fix.speedOverGroundKnots().get() * 10);
            else
                sog = 1023;
            dataSpeedOverGround.setShort(i, sog);
            // COG
            final short cog;
            if (fix.courseOverGroundDegrees().isPresent())
                cog = (short) Math.round(fix.courseOverGroundDegrees().get() * 10);
            else
                cog = 3600;
            dataCourseOverGround.setShort(i, cog);
            // heading
            final short heading;
            if (fix.headingDegrees().isPresent())
                heading = (short) Math.floor(fix.headingDegrees().get() + 0.01f);
            else
                heading = (short) 360;
            dataHeading.setShort(i, heading);
            // ais class
            byte aisClass;
            if (fix.aisClass() == AisClass.A)
                aisClass = (byte) 0;
            else
                aisClass = (byte) 1;
            dataAisClass.setByte(i, aisClass);
        }
        f.write(varLat, dataLat);
        f.write(varLon, dataLon);
        f.write(varTime, dataTime);
        f.write(varSource, dataSource);
        f.write(varLatency, dataLatency);
        f.write(varNavStatus, dataNavStatus);
        f.write(varRateOfTurn, dataRateOfTurn);
        f.write(varSpeedOverGround, dataSpeedOverGround);
        f.write(varCourseOverGround, dataCourseOverGround);
        f.write(varHeading, dataHeading);
        f.write(varAisClass, dataAisClass);
        f.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InvalidRangeException e) {
        throw new RuntimeException(e);
    }
}
Also used : Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) InvalidRangeException(ucar.ma2.InvalidRangeException) Dimension(ucar.nc2.Dimension) IOException(java.io.IOException) NetcdfFileWriter(ucar.nc2.NetcdfFileWriter) Array(ucar.ma2.Array)

Aggregations

Array (ucar.ma2.Array)30 IOException (java.io.IOException)17 Attribute (ucar.nc2.Attribute)17 Variable (ucar.nc2.Variable)15 Index (ucar.ma2.Index)14 ArrayFloat (ucar.ma2.ArrayFloat)11 Dimension (ucar.nc2.Dimension)10 NetcdfFile (ucar.nc2.NetcdfFile)10 File (java.io.File)9 InvalidRangeException (ucar.ma2.InvalidRangeException)9 WritableRaster (java.awt.image.WritableRaster)8 NetcdfFileWriteable (ucar.nc2.NetcdfFileWriteable)8 ArrayList (java.util.ArrayList)7 DataType (ucar.ma2.DataType)6 ArrayDouble (ucar.ma2.ArrayDouble)5 ArrayShort (ucar.ma2.ArrayShort)5 Array (com.beanit.openiec61850.Array)4 Array (org.openmuc.openiec61850.Array)4 ArrayInt (ucar.ma2.ArrayInt)4 Range (ucar.ma2.Range)4