Package kameleon.document2

Examples of kameleon.document2.Array


  public static byte[] convert(String srcPath, double a, double b) throws IOException {
    NetcdfFile ncfile = NetcdfFile.open(srcPath);
    try {
      Variable v = ncfile.findVariable("image1/image_data");
      Array array = v.read();

      int[] cmap = new int[256]; // palette
      cmap[0] = 0x00FFFFFF; // transparent and white
      for (int i = 1; i != 256; i++) {
        // 1 to 255 renders as (almost) white to black
        cmap[i] = 0xFF000000 | ((0xFF - i) * 0x010101);
      }
      IndexColorModel colorModel = new IndexColorModel(8,
              cmap.length, cmap, 0, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

      int[] shape = array.getShape();
      BufferedImage bi = new BufferedImage(shape[1], shape[0],BufferedImage.TYPE_BYTE_INDEXED, colorModel);

      Index index = array.getIndex();
      for (int y = 0; y < shape[0]; y++) {
        for (int x = 0; x < shape[1]; x++) {
          index.set(y, x);

          byte bval = array.getByte(index);
          double dval = v.isUnsigned() ? (double) DataType.unsignedByteToShort(bval) : (double) bval;

          //double dval = array.getDouble(index);
          // Fix for NetCDF returning all values larger than 127 as (value - 256):
          //if (dval < -1) {
View Full Code Here


    ncFile.setRedefineMode (true);
    ncFile.addVariable ("jill", DataType.DOUBLE, dims);
    ncFile.addVariableAttribute ("jill", "where", "up the hill");
    ncFile.setRedefineMode (false);

    Array jillArray = Array.factory (double.class, count, jillData);
    ncFile.write ("jill", start, jillArray);

    ncFile.flush();
    ncFile.close();

    NetcdfFile nc = NetcdfFile.open(filename, null);
    Variable v = nc.findVariable("jill");
    Array jillRead = v.read();
    CompareNetcdf.compareData(jillArray, jillRead);

    nc.close();
  }
View Full Code Here

    for (int i = 0; i < vars.size(); i++) {
      Variable vv = (Variable) vars.get(i);
      System.out.println(" " + vv.getShortName() + " == " + vv.getFullName());
    }

    Array data = v.read();
    assert data != null;
    assert data instanceof ArraySequence;

    ArraySequence as = (ArraySequence) data;
    as.getStructureDataCount();
View Full Code Here

    Variable v = ncfile.findVariable(varName);
    assert (null != v);
    int[] shape = v.getShape();

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

    int[] dataShape = A.getShape();
    assert dataShape.length == shape.length;
    for (int i = 0; i < shape.length; i++)
      assert dataShape[i] == shape[i];
    Section all = v.getShapeAsSection();
    System.out.println("  Entire dataset="+all);
View Full Code Here

  public static void testOne(Variable v, Section s, Array fullData) throws IOException, InvalidRangeException {
      System.out.println("   section="+s);

      // read just that
      Array sdata = v.read(s);
      assert sdata.getRank() == s.getRank();
      int[] sshape = sdata.getShape();
      for (int i = 0; i < sshape.length; i++)
        assert sshape[i] == s.getShape(i);

      // compare with logical section
      Array Asection = fullData.sectionNoReduce(s.getRanges());
      int[] ashape = Asection.getShape();
      assert (ashape.length == sdata.getRank());
      for (int i = 0; i < ashape.length; i++)
        assert sshape[i] == ashape[i];

      CompareNetcdf.compareData(sdata, Asection);
View Full Code Here

    ncfile.addStringVariable("t",new ArrayList<Dimension>(), trouble.length());
    ncfile.addVariableAttribute("t", "yow", trouble);

    ncfile.create();

    Array data = Array.factory(DataType.STRING, new int[0]);
    data.setObject( data.getIndex(), trouble);
    ncfile.writeStringData("t", data);
    ncfile.close();
  }
View Full Code Here

        NetcdfFile ncf = NetcdfFile.open( grib );
        Variable var = ncf.findVariable( parameter );
        Dimension dim = var.getDimension( 0 );
        String bounds = dim.getName() +"_bounds";
        Variable interval = ncf.findVariable( bounds );
        Array data = interval.read();
        IndexIterator iter = data.getIndexIterator();
        int idx = 0;
        while (iter.hasNext()) {
          int start = iter.getIntNext();
          int end = iter.getIntNext();
          if( start != tb[idx][0] || end != tb[idx][1]) {
View Full Code Here

    int[] shape = timeAxis.getShape();
    int ntimes = shape[0];
    assert (ntimes == dateList.size());

    DataType coordType = (timeAxis.getDataType() == DataType.STRING) ? DataType.STRING : DataType.DOUBLE;
    Array timeCoordVals = Array.factory(coordType, shape);
    IndexIterator ii = timeCoordVals.getIndexIterator();

    // check if its a String or a udunit
    if (timeAxis.getDataType() == DataType.STRING) {

      for (Date date : dateList) {
View Full Code Here

        out.print("  <netcdf id='" + dod.getId() + "' ");
        out.print("ncoords='" + dod.getNcoords(null) + "' >\n");

        for (CacheVar pv : cacheList) {
          Array data = pv.getData(dod.getId());
          if (data != null) {
            out.print("    <cache varName='" + pv.varName + "' >");
            NCdumpW.printArray(data, out);
            out.print("</cache>\n");
            if (logger.isDebugEnabled())
              logger.debug(" wrote array = " + pv.varName + " nelems= "+data.getSize()+" for "+dataset.getLocation());
          }
        }
        out.print("  </netcdf>\n");
      }
View Full Code Here

            //double took = .001 * .001 * .001 * (System.nanoTime() - start);
            //if (debugPersist) System.out.println("  split took = " + took + " sec; ");

            try {
              //start = System.nanoTime();
              Array data = Array.makeArray(pv.dtype, vals);
              //took = .001 * .001 * .001 * (System.nanoTime() - start);
              //if (debugPersist) System.out.println("  makeArray took = " + took + " sec nelems= "+data.getSize());
              pv.putData(id, data);
            } catch (Exception e) {
              logger.warn("Error reading cached data ",e);
View Full Code Here

TOP

Related Classes of kameleon.document2.Array

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.