Ejemplo n.º 1
0
 /** evaluate implicit function syntax; e.g., A1(5) or A1(A2) */
 public static Data implicit(Function f, Real r) {
   Data value = null;
   try {
     value = f.evaluate(r);
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return value;
 }
Ejemplo n.º 2
0
 /** evaluate the domainFactor function */
 public static visad.Field factor(FieldImpl f, VRealType rt) {
   visad.Field val = null;
   try {
     val = f.domainFactor(rt.getRealType());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return val;
 }
Ejemplo n.º 3
0
 /** evaluate the extract function */
 public static Data extract(visad.Field f, Real r) {
   Data d = null;
   try {
     d = f.extract((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return d;
 }
Ejemplo n.º 4
0
 /** evaluate the derive function */
 public static Data derive(Function f, VRealType rt) {
   Data val = null;
   try {
     val = f.derivative(rt.getRealType(), Data.NO_ERRORS);
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return val;
 }
Ejemplo n.º 5
0
 /** evaluate the dot operator */
 public static Data dot(TupleIface t, Real r) {
   Data d = null;
   try {
     d = t.getComponent((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return d;
 }
Ejemplo n.º 6
0
  public String longString(String pre) {
    FlatField fld = getAdaptedFlatField();
    if (fld == null) {
      return pre + "Cannot get cached FlatField";
    }

    try {
      return fld.longString(pre);
    } catch (VisADException e) {
      return pre + e.getMessage();
    }
  }
Ejemplo n.º 7
0
 /** evaluate the bracket function; e.g., A1[5] or A1[A2] */
 public static Data brackets(visad.Field f, Real r) {
   Data value = null;
   try {
     RealType rt = (RealType) r.getType();
     value = f.getSample((int) r.getValue());
   } catch (VisADException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   } catch (RemoteException exc) {
     if (FormulaVar.DEBUG) exc.printStackTrace();
   }
   return value;
 }
Ejemplo n.º 8
0
 // initialize above MathTypes
 static {
   try {
     image_type = MathType.stringToType("((ImageElement, ImageLine) -> ImageValue)");
     image_sequence_type = new FunctionType(RealType.Time, image_type);
     image_type2 = MathType.stringToType("((ImageElement, ImageLine) -> (ImageValue))");
     image_sequence_type2 = new FunctionType(RealType.Time, image_type2);
     image_type3 = MathType.stringToType("((ImageElement, ImageLine) -> (Red, Green, Blue))");
     image_sequence_type3 = new FunctionType(RealType.Time, image_type3);
   } catch (VisADException e) {
     throw new VisADError(e.getMessage());
   }
 }
Ejemplo n.º 9
0
  /**
   * Load the volume data to the display
   *
   * @throws RemoteException problem loading remote data
   * @throws VisADException problem loading the data
   */
  private void loadVolumeData() throws VisADException, RemoteException {
    Trace.call1("VRC.loadVolumeData");
    FieldImpl grid = getGridDataInstance().getGrid();
    FieldImpl newGrid = grid;

    if (getSkipValue() > 0) {
      grid = GridUtil.subset(grid, getSkipValue() + 1);
      newGrid = grid;
    }

    if (!usePoints) {
      // make sure the projection is correct before we start
      // transforming the data
      setProjectionInView(true, true);

      CoordinateSystem cs = getNavigatedDisplay().getDisplayCoordinateSystem();
      if ((cs != null) && (getNavigatedDisplay() instanceof MapProjectionDisplay)) {
        try {
          if (GridUtil.isConstantSpatialDomain(grid)) {
            newGrid = makeLinearGrid(grid, cs);
          } else {
            Set timeSet = GridUtil.getTimeSet(grid);
            for (int i = 0; i < timeSet.getLength(); i++) {
              FieldImpl timeField = makeLinearGrid((FieldImpl) grid.getSample(i, false), cs);
              if (i == 0) {
                FunctionType ft =
                    new FunctionType(
                        ((SetType) timeSet.getType()).getDomain(), timeField.getType());
                newGrid = new FieldImpl(ft, timeSet);
              }
              newGrid.setSample(i, timeField, false);
            }
          }
        } catch (VisADException ve) {
          ve.printStackTrace();
          userErrorMessage(
              "Can't render volume for "
                  + paramName
                  + " in this projection. Try using the data projection");
          newGrid = grid;
        }
      }
    }
    Trace.call1("VRC.loadVolumeData.loadData");
    myDisplay.loadData(newGrid);
    Trace.call2("VRC.loadVolumeData.loadData");
    Trace.call2("loadVolumeData");
  }
Ejemplo n.º 10
0
 public void actionPerformed(ActionEvent e) {
   String cmd = e.getActionCommand();
   if (cmd.equals("del")) {
     try {
       UnionSet set = (UnionSet) ref.getData();
       SampledSet[] sets = set.getSets();
       SampledSet[] new_sets = new SampledSet[sets.length - 1];
       System.arraycopy(sets, 0, new_sets, 0, sets.length - 1);
       ref.setData(new UnionSet(set.getType(), new_sets));
     } catch (VisADException ex) {
     } catch (RemoteException ex) {
     }
   } else if (cmd.equals("fill")) {
     UnionSet set = null;
     try {
       set = (UnionSet) ref.getData();
       System.out.println("area = " + DelaunayCustom.computeArea(set));
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     }
     try {
       // Irregular2DSet new_set = DelaunayCustom.fill(set);
       Irregular2DSet new_set = DelaunayCustom.fillCheck(set, false);
       if (new_ref == null) {
         new_ref = new DataReferenceImpl("fill");
         ConstantMap[] cmaps =
             new ConstantMap[] {
               new ConstantMap(1.0, Display.Blue),
               new ConstantMap(1.0, Display.Red),
               new ConstantMap(0.0, Display.Green)
             };
         DataRenderer renderer =
             (display instanceof DisplayImplJ3D)
                 ? (DataRenderer) new DefaultRendererJ3D()
                 : (DataRenderer) new DefaultRendererJ2D();
         renderer.suppressExceptions(true);
         display.addReferences(renderer, new_ref, cmaps);
       }
       new_ref.setData(new_set);
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     } catch (RemoteException ex) {
       System.out.println(ex.getMessage());
     }
   } else if (cmd.equals("lines")) {
     try {
       lines = !lines;
       GraphicsModeControl mode = display.getGraphicsModeControl();
       if (lines) {
         mode.setPolygonMode(DisplayImplJ3D.POLYGON_LINE);
       } else {
         mode.setPolygonMode(DisplayImplJ3D.POLYGON_FILL);
       }
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     } catch (RemoteException ex) {
       System.out.println(ex.getMessage());
     }
   }
 }
Ejemplo n.º 11
0
  /**
   * Get the data for the given DataChoice and selection criteria.
   *
   * @param dataChoice DataChoice for selection
   * @param category DataCategory for the DataChoice (not used)
   * @param subset subsetting criteria
   * @param requestProperties extra request properties
   * @return the Data object for the request
   * @throws RemoteException couldn't create a remote data object
   * @throws VisADException couldn't create the data
   */
  protected Data getDataInner(
      final DataChoice dataChoice,
      DataCategory category,
      final DataSelection subset,
      final Hashtable requestProperties)
      throws VisADException, RemoteException {

    try {
      List times = null;
      if (subset != null) {
        times = getTimesFromDataSelection(subset, dataChoice);
      }
      if (times == null) {
        times = dataChoice.getSelectedDateTimes();
      }

      List dtimes = subset.getTimeDriverTimes();

      if (dtimes != null && useDriverTime == false) {
        useDriverTime = true;
      }

      List<RadarAdapter> adapters = getAdapters();

      DateTime[] realDateTimes = new DateTime[adapters.size()];
      for (int i = 0; i < adapters.size(); i++) {
        realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime();
      }
      Arrays.sort(realDateTimes);
      // Flip it to get youngest date first
      boolean isRealTime = isRealTime();
      if (isRealTime) {
        realDateTimes =
            (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]);
      }
      // if use time driver
      if (useDriverTime) {
        List tests = resetTimesList(realDateTimes, times);
        if (!compareTimeLists(times, tests)) {
          reloadData();
          adapters = getAdapters();

          realDateTimes = new DateTime[adapters.size()];
          for (int i = 0; i < adapters.size(); i++) {
            realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime();
          }
          Arrays.sort(realDateTimes);
          // Flip it to get youngest date first
          isRealTime = isRealTime();
          if (isRealTime) {
            realDateTimes =
                (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]);
          }
          tests = resetTimesList(realDateTimes, times);
        }
        times = tests;
      }
      // if times are null, then that means all times
      DateTime[] dateTimes = null;

      if ((times == null) || (times.size() == 0)) {
        dateTimes = realDateTimes;
      } else {
        dateTimes = new DateTime[times.size()];
        for (int i = 0; i < times.size(); i++) {
          Object time = times.get(i);
          if (time instanceof TwoFacedObject) {
            int index = ((Integer) ((TwoFacedObject) time).getId()).intValue();
            dateTimes[i] = realDateTimes[index];
          } else if (time instanceof DateTime) {
            dateTimes[i] = (DateTime) time;
          }
        }
      }
      Arrays.sort(dateTimes);
      final Data[] datas = new Data[dateTimes.length];
      int timeIndex = 0;
      final MathType[] mt = {null};
      // create a new field of (Time -> (radar data)).
      // fill in the times array and data array with dates/data
      // only from those adapters which match the selected times.
      // if a data object is null, stick it in the list.
      // if all are null, then the MathType (mt) will never get set,
      // so return null.
      //            System.err.println ("Reading " + adapters.size() + " radar files");
      int cnt = 0;
      ThreadManager threadManager = new visad.util.ThreadManager("radar data reading");

      for (Iterator iter = adapters.iterator(); iter.hasNext(); ) {
        final RadarAdapter adapter = (RadarAdapter) iter.next();
        timeIndex = Arrays.binarySearch(dateTimes, adapter.getBaseTime());
        //              System.err.println ("timeIndex:" + timeIndex);
        if (timeIndex < 0) {
          continue;
        }
        cnt++;
        LogUtil.message("Time: " + (cnt) + "/" + dateTimes.length + " From:" + toString());
        final int theTimeIndex = timeIndex;
        threadManager.addRunnable(
            new visad.util.ThreadManager.MyRunnable() {
              public void run() throws Exception {
                Trace.call1("RDS.getData");
                Data d = adapter.getData(dataChoice, subset, requestProperties);
                Trace.call2("RDS.getData");
                datas[theTimeIndex] = d;
                if (d != null) {
                  mt[0] = d.getType();
                } else {
                }
              }
            });
      }

      try {
        // threadManager.debug = true;
        threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount());
      } catch (VisADException ve) {
        LogUtil.printMessage(ve.toString());
      }

      if (mt[0] == null) {
        return null;
      }

      FunctionType ft = new FunctionType(RealType.Time, mt[0]);
      SampledSet domainSet =
          (dateTimes.length == 1)
              ? (SampledSet) new SingletonSet(new RealTuple(dateTimes))
              : (SampledSet) DateTime.makeTimeSet(dateTimes);
      FieldImpl fi = new FieldImpl(ft, domainSet);
      fi.setSamples(datas, false);
      return fi;
    } catch (Exception exc) {
      logException("Creating obs", exc);
    }
    return null;
  }
Ejemplo n.º 12
0
  private FlatField getAdaptedFlatField() {
    // if owner array is null,
    //  assume this object got serialized & unserialized
    if (adaptedFlatFieldOwner == null) {
      return null;
    }

    synchronized (adaptedFlatFields) {
      for (int ii = 0; ii < MAX_FILE_FLAT_FIELDS; ii++) {
        if (this == adaptedFlatFieldOwner[ii]) {

          // mark time of most recent access

          adaptedFlatFieldTimes[ii] = System.currentTimeMillis();

          return adaptedFlatFields[ii];
        }
      }

      // this FileFlatField does not own a cache entry, so invoke
      // CahceStrategy.allocate to allocate one, possibly by taking
      // one, possibly by taking one from another FileFlatField;
      // this will be an area for lots of thought and experimentation;

      adaptedFlatFieldIndex =
          cacheStrategy.allocate(
              adaptedFlatFields, adaptedFlatFieldDirty,
              adaptedFlatFieldSizes, adaptedFlatFieldTimes);

      // flush cache entry, if dirty

      if (adaptedFlatFieldDirty[adaptedFlatFieldIndex]) {
        try {
          adaptedFlatFieldOwner[adaptedFlatFieldIndex].flushCache();
        } catch (VisADException e) {
          System.out.println(e.getMessage());
        }
      }

      // create a new entry in adaptedFlatFields at adaptedFlatFieldIndex
      // and read data values from fileAccessor at fileLocation
      try {
        adaptedFlatFields[adaptedFlatFieldIndex] = fileAccessor.getFlatField();
      } catch (VisADException e1) {
        System.out.println(e1.getMessage());
      } catch (RemoteException e2) {
        System.out.println(e2.getMessage());
      }

      // mark cache entry as belonging to this FileFlatField

      adaptedFlatFieldOwner[adaptedFlatFieldIndex] = this;

      // get size of adapted FlatField
      // (by calling a method that currently does not exist)

      /*adaptedFlatFields[adaptedFlatFieldIndex].getSize(); */

      adaptedFlatFieldTimes[adaptedFlatFieldIndex] = System.currentTimeMillis();

      return adaptedFlatFields[adaptedFlatFieldIndex];
    }
  }
Ejemplo n.º 13
0
  public synchronized void drag_direct(VisADRay ray, boolean first, int mouseModifiers) {
    if (barbValues == null || ref == null || shadow == null) return;

    if (first) {
      stop = false;
    } else {
      if (stop) return;
    }

    // modify direction if mshift != 0
    // modify speed if mctrl != 0
    // modify speed and direction if neither
    int mshift = mouseModifiers & InputEvent.SHIFT_MASK;
    int mctrl = mouseModifiers & InputEvent.CTRL_MASK;

    float o_x = (float) ray.position[0];
    float o_y = (float) ray.position[1];
    float o_z = (float) ray.position[2];
    float d_x = (float) ray.vector[0];
    float d_y = (float) ray.vector[1];
    float d_z = (float) ray.vector[2];

    if (pickCrawlToCursor) {
      if (first) {
        offset_count = OFFSET_COUNT_INIT;
      } else {
        if (offset_count > 0) offset_count--;
      }
      if (offset_count > 0) {
        float mult = ((float) offset_count) / ((float) OFFSET_COUNT_INIT);
        o_x += mult * offsetx;
        o_y += mult * offsety;
        o_z += mult * offsetz;
      }
    }

    if (first || refirst) {
      point_x = barbValues[2];
      point_y = barbValues[3];
      point_z = 0.0f;
      line_x = 0.0f;
      line_y = 0.0f;
      line_z = 1.0f; // lineAxis == 2 in DataRenderer.drag_direct
    } // end if (first || refirst)

    float[] x = new float[3]; // x marks the spot
    // DirectManifoldDimension = 2
    // intersect ray with plane
    float dot = (point_x - o_x) * line_x + (point_y - o_y) * line_y + (point_z - o_z) * line_z;
    float dot2 = d_x * line_x + d_y * line_y + d_z * line_z;
    if (dot2 == 0.0) return;
    dot = dot / dot2;
    // x is intersection
    x[0] = o_x + dot * d_x;
    x[1] = o_y + dot * d_y;
    x[2] = o_z + dot * d_z;
    /*
    System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
    */
    try {

      Tuple data = (Tuple) link.getData();
      int n = ((TupleType) data.getType()).getNumberOfRealComponents();
      Real[] reals = new Real[n];

      int k = 0;
      int m = data.getDimension();
      for (int i = 0; i < m; i++) {
        Data component = data.getComponent(i);
        if (component instanceof Real) {
          reals[k++] = (Real) component;
        } else if (component instanceof RealTuple) {
          for (int j = 0; j < ((RealTuple) component).getDimension(); j++) {
            reals[k++] = (Real) ((RealTuple) component).getComponent(j);
          }
        }
      }

      if (first || refirst) {
        // get first Data flow vector
        for (int i = 0; i < 3; i++) {
          int j = flowToComponent[i];
          data_flow[i] = (j >= 0) ? (float) reals[j].getValue() : 0.0f;
        }

        if (coord != null) {
          float[][] ds = {{data_flow[0]}, {data_flow[1]}, {data_flow[2]}};
          ds = coord.toReference(ds);
          data_flow[0] = ds[0][0];
          data_flow[1] = ds[1][0];
          data_flow[2] = ds[2][0];
        }

        data_speed =
            (float)
                Math.sqrt(
                    data_flow[0] * data_flow[0]
                        + data_flow[1] * data_flow[1]
                        + data_flow[2] * data_flow[2]);
        float barb0 = barbValues[2] - barbValues[0];
        float barb1 = barbValues[3] - barbValues[1];
        /*
        System.out.println("data_flow = " + data_flow[0] + " " + data_flow[1] +
                           " " + data_flow[2]);
        System.out.println("barbValues = " + barbValues[0] + " " + barbValues[1] +
                           "   " + barbValues[2] + " " + barbValues[3]);
        System.out.println("data_speed = " + data_speed);
        */
      } // end if (first || refirst)

      // convert x to a flow vector, and from spatial to earth
      if (getRealVectorTypes(which_barb) instanceof EarthVectorType) {
        // don't worry about vector magnitude -
        // data_speed & display_speed take care of that
        float eps = 0.0001f; // estimate derivative with a little vector
        float[][] spatial_locs = {
          {barbValues[0], barbValues[0] + eps * (x[0] - barbValues[0])},
          {barbValues[1], barbValues[1] + eps * (x[1] - barbValues[1])},
          {0.0f, 0.0f}
        };
        /*
        System.out.println("spatial_locs = " + spatial_locs[0][0] + " " +
                           spatial_locs[0][1] + " " + spatial_locs[1][0] + " " +
                           spatial_locs[1][1]);
        */
        float[][] earth_locs = spatialToEarth(spatial_locs);
        // WLH - 18 Aug 99
        if (earth_locs == null) return;
        /*
        System.out.println("earth_locs = " + earth_locs[0][0] + " " +
                           earth_locs[0][1] + " " + earth_locs[1][0] + " " +
                           earth_locs[1][1]);
        */
        x[2] = 0.0f;
        x[0] =
            (earth_locs[1][1] - earth_locs[1][0])
                * ((float) Math.cos(Data.DEGREES_TO_RADIANS * earth_locs[0][0]));
        x[1] = earth_locs[0][1] - earth_locs[0][0];
        /*
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else { // if (!(getRealVectorTypes(which_barb) instanceof EarthVectorType))
        // convert x to vector
        x[0] -= barbValues[0];
        x[1] -= barbValues[1];

        // adjust for spatial map scalings but don't worry about vector
        // magnitude - data_speed & display_speed take care of that
        // also, spatial is Cartesian
        double[] ranges = getRanges();
        for (int i = 0; i < 3; i++) {
          x[i] /= ranges[i];
        }
        /*
        System.out.println("ranges = " + ranges[0] + " " + ranges[1] +
                           " " + ranges[2]);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      }

      // WLH 6 August 99
      x[0] = -x[0];
      x[1] = -x[1];
      x[2] = -x[2];

      /* may need to do this for performance
            float[] xx = {x[0], x[1], x[2]};
            addPoint(xx);
      */

      float x_speed = (float) Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
      /* WLH 16 April 2002 - from Ken
            if (x_speed < 0.000001f) x_speed = 0.000001f;
      */
      if (x_speed < 0.01f) x_speed = 0.01f;
      if (first || refirst) {
        display_speed = x_speed;
      }
      refirst = false;

      if (mshift != 0) {
        // only modify data_flow direction
        float ratio = data_speed / x_speed;
        x[0] *= ratio;
        x[1] *= ratio;
        x[2] *= ratio;
        /*
        System.out.println("direction, ratio = " + ratio + " " +
                           data_speed + " " + x_speed);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else if (mctrl != 0) {
        // only modify data_flow speed
        float ratio = x_speed / display_speed;
        if (data_speed < EPS) {
          data_flow[0] = 2.0f * EPS;
          refirst = true;
        }
        x[0] = ratio * data_flow[0];
        x[1] = ratio * data_flow[1];
        x[2] = ratio * data_flow[2];
        /*
        System.out.println("speed, ratio = " + ratio + " " +
                           x_speed + " " + display_speed);
        System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]);
        */
      } else {
        // modify data_flow speed and direction
        float ratio = data_speed / display_speed;
        /*
        System.out.println("data_speed = " + data_speed +
                           " display_speed = " + display_speed +
                           " ratio = " + ratio + " EPS = " + EPS);
        System.out.println("x = " + x[0] + " " + x[1] +" " + x[2] +
                           " x_speed = " + x_speed);
          data_speed = 21.213203 display_speed = 0.01 ratio = 2121.3203 EPS = 0.2
          x = 1.6170928E-4 1.6021729E-4 -0.0 x_speed = 0.01
          wind = (0.3430372, 0.33987218) at (-35.0, 5.0)
        */
        if (data_speed < EPS) {
          data_flow[0] = 2.0f * EPS;
          x[0] = data_flow[0];
          x[1] = data_flow[1];
          x[2] = data_flow[2];
          refirst = true;
        } else {
          x[0] *= ratio;
          x[1] *= ratio;
          x[2] *= ratio;
        }
      }

      if (coord != null) {
        float[][] xs = {{x[0]}, {x[1]}, {x[2]}};
        xs = coord.fromReference(xs);
        x[0] = xs[0][0];
        x[1] = xs[1][0];
        x[2] = xs[2][0];
      }

      // now replace flow values
      Vector vect = new Vector();
      for (int i = 0; i < 3; i++) {
        int j = flowToComponent[i];
        if (j >= 0) {
          RealType rtype = (RealType) reals[j].getType();
          reals[j] = new Real(rtype, (double) x[i], rtype.getDefaultUnit(), null);

          // WLH 31 Aug 2000
          Real r = reals[j];
          Unit overrideUnit = null;
          if (directMap[i] != null) {
            overrideUnit = directMap[i].getOverrideUnit();
          }
          Unit rtunit = rtype.getDefaultUnit();
          // units not part of Time string
          if (overrideUnit != null
              && !overrideUnit.equals(rtunit)
              && !RealType.Time.equals(rtype)) {
            double d = (float) overrideUnit.toThis((double) x[0], rtunit);
            r = new Real(rtype, d, overrideUnit);
            String valueString = r.toValueString();
            vect.addElement(rtype.getName() + " = " + valueString);
          } else {
            // create location string
            vect.addElement(rtype.getName() + " = " + x[i]);
          }
        }
      }
      getDisplayRenderer().setCursorStringVector(vect);

      Data newData = null;
      // now build new RealTuple or Flat Tuple
      if (data instanceof RealTuple) {
        newData =
            new RealTuple(
                ((RealTupleType) data.getType()), reals, ((RealTuple) data).getCoordinateSystem());
      } else {
        Data[] new_components = new Data[m];
        k = 0;
        for (int i = 0; i < m; i++) {
          Data component = data.getComponent(i);
          if (component instanceof Real) {
            new_components[i] = reals[k++];
          } else if (component instanceof RealTuple) {
            Real[] sub_reals = new Real[((RealTuple) component).getDimension()];
            for (int j = 0; j < ((RealTuple) component).getDimension(); j++) {
              sub_reals[j] = reals[k++];
            }
            new_components[i] =
                new RealTuple(
                    ((RealTupleType) component.getType()),
                    sub_reals,
                    ((RealTuple) component).getCoordinateSystem());
          }
        }
        newData = new Tuple(new_components, false);
      }
      ref.setData(newData);
    } catch (VisADException e) {
      // do nothing
      System.out.println("drag_direct " + e);
      e.printStackTrace();
    } catch (RemoteException e) {
      // do nothing
      System.out.println("drag_direct " + e);
      e.printStackTrace();
    }
  }