Package org.modeshape.jcr.api

Examples of org.modeshape.jcr.api.JcrTools$Variable


                    }

                }

                Dimension dim       = ds.findDimension("MSL_alt");
                Variable  dimV      = ds.findVariable("MSL_alt");
                Array     dimU      = dimV.read();
                int       inscr = (dimU.getFloat(1) - dimU.getFloat(0)) > 0
                                  ? 1
                                  : 0;
                int       n         = dim.getLength();
                double    incr      = (stop - start) / n;

                String    timeUnits = "seconds since 1980-01-06 00:00:00";
                Variable timeVar = new VariableDS(ds, null, null, "time",
                                       DataType.DOUBLE, dim.getName(),
                                       timeUnits, null);
                ds.addVariable(null, timeVar);
                timeVar.addAttribute(new Attribute("units", timeUnits));
                timeVar.addAttribute(new Attribute(_Coordinate.AxisType,
                        AxisType.Time.toString()));
                int dir = ds.readAttributeInteger(null, "irs", 1);
                ArrayDouble.D1 data =
                    (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                        new int[] { n });
                if (inscr == 0) {
                    if (dir == 1) {
                        for (int i = 0; i < n; i++) {
                            data.set(i, start + i * incr);
                        }
                    } else {
                        for (int i = 0; i < n; i++) {
                            data.set(i, stop - i * incr);
                        }
                    }
                } else {
                    for (int i = 0; i < n; i++) {
                        data.set(i, stop - i * incr);
                    }
                }
                timeVar.setCachedData(data, false);
            }

            Variable v = ds.findVariable("Lat");
            if (v == null) {
                v = ds.findVariable("GEO_lat");
            }
            v.addAttribute(new Attribute(_Coordinate.AxisType,
                                         AxisType.Lat.toString()));
            Variable v1 = ds.findVariable("Lon");
            if (v1 == null) {
                v1 = ds.findVariable("GEO_lon");
            }
            v1.addAttribute(new Attribute(_Coordinate.AxisType,
                                          AxisType.Lon.toString()));
        } else {
            Dimension dim = ds.findDimension("time");
            int       n   = dim.getLength();
            Variable latVar = new VariableDS(ds, null, null, "Lat",
                                             DataType.FLOAT, dim.getName(),
                                             "degree", null);
            latVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Lat.toString()));
            ds.addVariable(null, latVar);
            Variable lonVar = new VariableDS(ds, null, null, "Lon",
                                             DataType.FLOAT, dim.getName(),
                                             "degree", null);
            lonVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Lon.toString()));
            ds.addVariable(null, lonVar);
            Variable altVar = new VariableDS(ds, null, null, "MSL_alt",
                                             DataType.FLOAT, dim.getName(),
                                             "meter", null);
            altVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Height.toString()));
            ds.addVariable(null, altVar);

            // cal data array
            ArrayFloat.D1 latData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayFloat.D1 lonData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayFloat.D1 altData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayDouble.D1 timeData =
                (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                    new int[] { n });
            this.conventionName = "Cosmic3";

            int iyr  = ds.readAttributeInteger(null, "year", 2009);
            int mon  = ds.readAttributeInteger(null, "month", 0);
            int iday = ds.readAttributeInteger(null, "day", 0);
            int ihr  = ds.readAttributeInteger(null, "hour", 0);
            int min  = ds.readAttributeInteger(null, "minute", 0);
            int sec  = ds.readAttributeInteger(null, "second", 0);

            double start = ds.readAttributeDouble(null, "startTime",
                               Double.NaN);
            double stop = ds.readAttributeDouble(null, "stopTime",
                              Double.NaN);
            double incr = (stop - start) / n;
            int    t    = 0;
            // double julian = juday(mon, iday, iyr);
            // cal the dtheta based pm attributes
            double   dtheta = gast(iyr, mon, iday, ihr, min, sec, t);

            Variable tVar   = ds.findVariable("time");
            String timeUnits = "seconds since 1980-01-06 00:00:00"//dtime.getUnit().toString();
            tVar.removeAttributeIgnoreCase("valid_range");
            tVar.removeAttributeIgnoreCase("units");
            tVar.addAttribute(new Attribute("units", timeUnits));
            tVar.addAttribute(new Attribute(_Coordinate.AxisType,
                                            AxisType.Time.toString()));

            Variable v    = ds.findVariable("xLeo");
            Array    xLeo = v.read();
            v = ds.findVariable("yLeo");
            Array yLeo = v.read();
            v = ds.findVariable("zLeo");
            Array         zLeo   = v.read();
            Array         tArray = tVar.read();
            double        pi     = 3.1415926;
            double        a      = 6378.1370;
            double        b      = 6356.7523142;
            IndexIterator iiter0 = xLeo.getIndexIterator();
View Full Code Here


  public void testReadCompressedInt() throws IOException {
    // actually doesnt seem to be compressed ??

    NetcdfFile ncfile = TestH5.openH5("support/zip.h5");
    Variable dset = ncfile.findVariable("Data/Compressed_Data");
    assert dset != null;
    assert(dset.getDataType() == DataType.INT);

    assert(dset.getRank() == 2);
    assert(dset.getShape()[0] == 1000);
    assert(dset.getShape()[1] == 20);

    // read entire array
    Array A = dset.read();
    assert(A.getRank() == 2);
    assert(A.getShape()[0] == 1000);
    assert(A.getShape()[1] == 20);

    int[] shape = A.getShape();
View Full Code Here

  public void testReadCompressedByte() throws IOException {
    // actually doesnt seem to be compressed ??

    NetcdfFile ncfile = TestH5.openH5("msg/MSG1_8bit_HRV.H5");
    Variable dset = ncfile.findVariable("image1/image_preview");
    assert dset != null;
    assert(dset.getDataType() == DataType.BYTE);

    assert(dset.getRank() == 2);
    assert(dset.getShape()[0] == 64);
    assert(dset.getShape()[1] == 96);

    // read entire array
    Array A = dset.read();
    assert(A.getRank() == 2);
    assert(A.getShape()[0] == 64);
    assert(A.getShape()[1] == 96);

    byte[] firstRow = new byte[] {
View Full Code Here

  }

  public void testEndian() throws IOException {
    String testDir = TestN4.testDir;
    NetcdfFile ncfile = TestNC2.open(testDir+"endianTest.nc4");
    Variable v = ncfile.findVariable("TMP");
    assert v != null;
    assert v.getDataType() == DataType.FLOAT;

    Array data = v.read();
    assert data.getElementType() == float.class;

    //large values indicate incorrect inflate or byte swapping
    while (data.hasNext()) {
      float val = data.nextFloat();
View Full Code Here

  }

  public void testReadArrayType() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/SDS_array_type.h5");

    Variable dset = null;
    assert(null != (dset = ncfile.findVariable("IntArray")));
    assert(dset.getDataType() == DataType.INT);

    assert(dset.getRank() == 3);
    assert(dset.getShape()[0] == 10);
    assert(dset.getShape()[1] == 5);
    assert(dset.getShape()[2] == 4);

    // read entire array
    Array A;
    try {
      A = dset.read();
    }
    catch (IOException e) {
      System.err.println("ERROR reading file");
      assert(false);
      return;
    }
    assert(A.getRank() == 3);

    Index ima = A.getIndex();
    int[] shape = A.getShape();

    for (int i = 0; i < shape[0]; i++)
      for (int j = 0; j < shape[1]; j++)
        for (int k = 0; k < shape[2]; k++)
          if (A.getInt(ima.set(i, j, k)) != i) {
            assert false;
          }


          // read part of array
    dset.setCachedData(null, false); // turn off caching to test read subset
    dset.setCaching(false);
    int[] origin2 = new int[3];
    int[] shape2 = new int[] {
        10, 1, 1};
    try {
      A = dset.read(origin2, shape2);
    }
    catch (InvalidRangeException e) {
      System.err.println("ERROR reading file " + e);
      assert(false);
      return;
View Full Code Here

  }

  public void testVlengthVariableChunked() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/uvlstr.h5");

    Variable v = ncfile.findVariable("Space1");
    assert (null != v);
    assert (v.getDataType() == DataType.STRING);
    assert (v.getRank() == 1);
    assert (v.getShape()[0] == 9);

    try {
      Array data = v.read();
      assert (data.getElementType() == String.class);
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        out.println(iter.next());
      }

    } catch (IOException e) {
      e.printStackTrace();
      assert false;
    }

    int[] origin = new int[]{3};
    int[] shape = new int[]{3};
    try {
      Array data2 = v.read(origin, shape);
      Index ima = data2.getIndex();
      assert (data2.getElementType() == String.class);
      assert (data2 instanceof ArrayObject);
      assert ((String) data2.getObject(ima.set(0))).startsWith("testing whether that nation");
      assert ((String) data2.getObject(ima.set(1))).startsWith("O Gloria inmarcesible!");
View Full Code Here

  } // */

  public void testVlengthVariable() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/vlslab.h5");

    Variable v = ncfile.findVariable("Space1");
    assert (null != v);
    assert (v.getDataType() == DataType.STRING);
    assert (v.getRank() == 1);
    assert (v.getShape()[0] == 12);

    try {
      Array data = v.read();
      assert (data.getElementType() == String.class);
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        out.println(iter.next());
      }

    } catch (IOException e) {
      assert false;
    }

    int[] origin = new int[]{4};
    int[] shape = new int[]{1};
    try {
      Array data2 = v.read(origin, shape);
      Index ima = data2.getIndex();
      assert (data2.getElementType() == String.class);
      assert (data2 instanceof ArrayObject);
      assert ((String) data2.getObject(ima.set(0))).equals("Five score and seven years ago our forefathers brought forth on this continent a new nation,");
    }
View Full Code Here

  }

  private void testVlenEndian(String filename, int n) throws IOException {
    NetcdfFile ncfile = NetcdfDataset.openFile(filename, null);

    Variable v = ncfile.findVariable("levels");
    assert (null != v);
    assert (v.getDataType() == DataType.INT);
    assert (v.getRank() == 2);
    assert (v.getShape()[0] == n) : v.getShape()[0];

    try {
      Array data = v.read();
      // assert(data.getElementType() instanceof ucar.ma2.ArrayInt.class) : data.getElementType();
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        Array inner = (Array) iter.next();
View Full Code Here

  }

  public void test1() throws IOException {
    //H5header.setDebugFlags( new ucar.nc2.util.DebugFlagsImpl("H5header/header"));
    NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS1_v4.0.2a-aIrix-c2_2003d106.he5");
    Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS_L1_Swath/Data Fields/Scaled Ch01 Radiance");
    dset.read();
  }
View Full Code Here

    dset.read();
  }

  public void test2() throws IOException {
    NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS2-AFGL_b027_na.he5");
    Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS/Data Fields/Altitude");
   
    //H5header.setDebugFlags( new ucar.nc2.util.DebugFlagsImpl("H5header/dataBtree"));
    Array data = dset.read();
    assert data.getElementType() == float.class;
  }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.api.JcrTools$Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.