Package ucar.ma2

Examples of ucar.ma2.StructureDataIterator


        Array dataArray =
            Array.factory(v2.getDataType().getPrimitiveClassType(),
                          section.getShape());

        Index dataIndex = dataArray.getIndex();

        if (varname.equals("latitude") || varname.equals("longitude")) {
            double[][] pixel = new double[2][1];
            double[][] latLon;
            double[][][] latLonValues =
                new double[geoXRange.length()][geoYRange.length()][2];

            // Use Range object, which calculates requested i, j
            // values and incorporates stride
            for (int i = 0; i < geoXRange.length(); i++) {
                for (int j = 0; j < geoYRange.length(); j++) {
                    pixel[0][0] = (double) geoXRange.element(i);
                    pixel[1][0] = (double) geoYRange.element(j);
                    latLon      = nav.toLatLon(pixel);

                    if (varname.equals("lat")) {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[0][0]));
                    } else {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[1][0]));
                    }
                }
            }
        }

        if (varname.equals("image")) {
            try {
                int[][] pixelData = new int[1][1];
                if (bandRange != null) {
                    for (int k = 0; k < bandRange.length(); k++) {
                        int bandIndex = bandRange.element(k) + 1// band numbers in McIDAS are 1 based
                        for (int j = 0; j < geoYRange.length(); j++) {
                            for (int i = 0; i < geoXRange.length(); i++) {
                                pixelData = af.getData(geoYRange.element(j),
                                        geoXRange.element(i), 1, 1,
                                        bandIndex);
                                dataArray.setInt(dataIndex.set(0, k, j, i),
                                        (pixelData[0][0]));
                            }
                        }
                    }

                } else {
                    for (int j = 0; j < geoYRange.length(); j++) {
                        for (int i = 0; i < geoXRange.length(); i++) {
                            pixelData = af.getData(geoYRange.element(j),
                                    geoXRange.element(i), 1, 1);
                            dataArray.setInt(dataIndex.set(0, j, i),
                                             (pixelData[0][0]));
                        }
                    }

                }
View Full Code Here


                    var=varList.get(ix);
                    if ((var.getShortName()).equals("numGates")) { numGates=var; break}
                }
            }
            ArrayInt.D1 gatesArr=(ArrayInt.D1) Array.factory(DataType.INT, numGates.getShape());
            Index gatesIndex=gatesArr.getIndex();
           
            for (int i=0; i<number_sweeps; i++) {
                List rlist = sgp[i];
                for (int jj=0; jj<num_rays; jj++) { rtemp[jj]=(Ray)rlist.get(jj); } //ray[i][jj]; }
                ngates=rtemp[0].getBins();
                gatesArr.setInt(gatesIndex.set(i), ngates);
            }

            for (int i=0; i<number_sweeps; i++) {
                distanceR[i].setCachedData(distArr[i], false);
                time[i].setCachedData(timeArr[i], false);
View Full Code Here

                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         yRange    = section.getRange(rangeIdx++);
        Range         xRange    = section.getRange(rangeIdx);

        IndexIterator ii        = dataArray.getIndexIterator();

        // loop over ens
        for (int ensIdx = ensRange.first(); ensIdx <= ensRange.last();
                ensIdx += ensRange.stride()) {
            //loop over time
View Full Code Here

              ? 1
              : nk); k++) {
            origin[0] = i;
            origin[1] = j;
            origin[2] = k;
            IndexIterator it = array.section(origin,
                eshape).getIndexIterator();
            for (int l = 0; l < n; l++) {
              d[l] = it.getDoubleNext()//get the original values
            }
            double[] d2 = extrapinterpolate(d)//compute new values
            //define slice of new array to write into
            IndexIterator newit =
                newArray.section(origin,
                    neweshape).getIndexIterator();
            for (int l = 0; l < n + 1; l++) {
              newit.setDoubleNext(d2[l]);
            }
          }
        }
      }
    } catch (InvalidRangeException e) {
View Full Code Here

  static public void compareData(Array data1, Array data2) {
    assert data1.getSize() == data2.getSize();
    assert data1.getElementType() == data2.getElementType() : data1.getElementType()+"!="+ data2.getElementType();
    DataType dt = DataType.getType( data1.getElementType());

    IndexIterator iter1 = data1.getIndexIterator();
    IndexIterator iter2 = data2.getIndexIterator();

    if (dt == DataType.DOUBLE) {
      while (iter1.hasNext()) {
          double v1 = iter1.getDoubleNext();
          double v2 = iter2.getDoubleNext();
          if (!Double.isNaN(v1) || !Double.isNaN(v2))
            assert v1 == v2 : v1 + " != "+ v2+" count="+iter1;
      }
    }

    else if (dt == DataType.FLOAT) {
      while (iter1.hasNext()) {
          float v1 = iter1.getFloatNext();
          float v2 = iter2.getFloatNext();
          if (!Float.isNaN(v1) || !Float.isNaN(v2))
            assert v1 == v2 : v1 + " != "+ v2+" count="+iter1;
      }
    }

    else if (dt == DataType.INT) {
      while (iter1.hasNext()) {
          int v1 = iter1.getIntNext();
          int v2 = iter2.getIntNext();
          assert v1 == v2 : v1 + " != "+ v2+" count="+iter1;
      }
    }

    else if (dt == DataType.SHORT) {
      while (iter1.hasNext()) {
          short v1 = iter1.getShortNext();
          short v2 = iter2.getShortNext();
          assert v1 == v2 : v1 + " != "+ v2+" count="+iter1;
      }
    }

    else if (dt == DataType.BYTE) {
      while (iter1.hasNext()) {
          byte v1 = iter1.getByteNext();
          byte v2 = iter2.getByteNext();
          assert v1 == v2 : v1 + " != "+ v2+" count="+iter1;
      }
    }
  }
View Full Code Here

     // Range scanRange = section.getRange(0);
     // Range radialRange = section.getRange(1);
     // Range gateRange = section.getRange(2);

      Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape());
      IndexIterator ii = data.getIndexIterator();

      List groups = null;
      String shortName = v2.getShortName();
      if( shortName.startsWith("Reflectivity"))
        groups = volScan.getReflectivityGroups();
View Full Code Here

    public long readToByteChannel11(ucar.nc2.Variable v2, Section section, WritableByteChannel channel)
    throws java.io.IOException, ucar.ma2.InvalidRangeException {
        Array data = readData(v2, section);
        float[] ftdata=new float[(int)data.getSize()];
        byte[] bytedata=new byte[(int)data.getSize()*4];
        IndexIterator iter=data.getIndexIterator();
        int i=0;
        ByteBuffer buffer=ByteBuffer.allocateDirect(bytedata.length);
        while (iter.hasNext()) { ftdata[i]=iter.getFloatNext();
        bytedata[i]=new Float(ftdata[i]).byteValue();
        buffer.put(bytedata[i]);
        i++;
        }
        buffer=ByteBuffer.wrap(bytedata);
View Full Code Here

    // create the data and the variable
    try { // p(k) = p0 * exp(-lev(k))
      double p0 = p0Var.readScalarDouble();
      Array levelData = levelVar.read();
      Array pressureData = Array.factory(double.class, levelData.getShape());
      IndexIterator ii = levelData.getIndexIterator();
      IndexIterator iip = pressureData.getIndexIterator();
      while (ii.hasNext()) {
        double val = p0 * Math.exp(-1.0 * ii.getDoubleNext());
        iip.setDoubleNext(val);
      }

      CoordinateAxis1D p = new CoordinateAxis1D(ds, null, v.getShortName() + "_pressure", DataType.DOUBLE,
              levelVar.getDimensionsString(), units,
              "Vertical Pressure coordinate synthesized from atmosphere_ln_pressure_coordinate formula");
View Full Code Here

        Array dataArray = Array.factory(DataType.FLOAT, section.getShape());
        GradsVariable gradsVar = findVar(v2);

        // Canonical ordering is ens, time, level, lat, lon
        int           rangeIdx  = 0;
        Range         ensRange  = (gradsDDF.getEnsembleDimension() != null)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         timeRange = (section.getRank() > 2)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         levRange  = (gradsVar.getNumLevels() > 0)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         yRange    = section.getRange(rangeIdx++);
        Range         xRange    = section.getRange(rangeIdx);

        IndexIterator ii        = dataArray.getIndexIterator();

        // loop over ens
        for (int ensIdx = ensRange.first(); ensIdx <= ensRange.last();
View Full Code Here

    // create the List<Dim>
    // Section shifted = intersect.shiftOrigin(dataSection); // want reletive to dataSection
    int wantStride = 1;
    int dataStride = 1;
    for (int ii = varRank - 1; ii >= 0; ii--) {
      Range dr = dataSection.getRange(ii);
      Range wr = wantSection.getRange(ii);
      Range ir = intersect.getRange(ii);
      dimList.add(new Dim(dr, wr, ir, dataStride, wantStride)); // note reversed : fastest first
      dataStride *= dr.length();
      wantStride *= wr.length();
    }

View Full Code Here

TOP

Related Classes of ucar.ma2.StructureDataIterator

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.