Esempio n. 1
1
    // create from a dataset
    public VariableBean(Variable vs) {
      this.vs = vs;
      // vs = (v instanceof VariableEnhanced) ? (VariableEnhanced) v : new VariableStandardized( v);

      setName(vs.getShortName());
      setDescription(vs.getDescription());
      setUnits(vs.getUnitsString());
      setDataType(vs.getDataType().toString());

      // Attribute csAtt = vs.findAttribute("_coordSystems");
      // if (csAtt != null)
      //  setCoordSys( csAtt.getStringValue());

      // collect dimensions
      StringBuilder lens = new StringBuilder();
      StringBuilder names = new StringBuilder();
      java.util.List dims = vs.getDimensions();
      for (int j = 0; j < dims.size(); j++) {
        ucar.nc2.Dimension dim = (ucar.nc2.Dimension) dims.get(j);
        if (j > 0) {
          lens.append(",");
          names.append(",");
        }
        String name = dim.isShared() ? dim.getName() : "anon";
        names.append(name);
        lens.append(dim.getLength());
      }
      setDimensions(names.toString());
      setShape(lens.toString());
    }
Esempio n. 2
0
  public void readByte2Short() throws Exception {
    Variable t2 = null;
    assert (null != (t2 = ncfileRead.findVariable("t2")));
    assert (t2.getDataType() == DataType.BYTE);

    Attribute att = t2.findAttribute(CDM.SCALE_FACTOR);
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    assert (2 == att.getNumericValue().doubleValue());
    assert (DataType.SHORT == att.getDataType());

    assert (null != (t2 = dsRead.findVariable("t2")));
    assert t2 instanceof VariableEnhanced;
    VariableDS vs = (VariableDS) t2;
    assert (vs.getDataType() == DataType.SHORT) : vs.getDataType();
    assert (!vs.hasMissing());

    Array A = vs.read();
    assert (A.getElementType() == short.class) : A.getElementType();
    Index ima = A.getIndex();
    int[] shape = A.getShape();
    int i, j;
    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getShort(ima.set(i, j)) == (2 * (i * 10 + j) + 77));
      }
    }
    System.out.println("**************TestStandardVar readByte2Short");
  }
  public void resetFrom(TemplateImpl another) {
    removeAllParsed();
    toParseSegments = another.toParseSegments;

    myKey = another.getKey();
    myString = another.myString;
    myTemplateText = another.myTemplateText;
    myGroupName = another.myGroupName;
    myId = another.myId;
    myDescription = another.myDescription;
    myShortcutChar = another.myShortcutChar;
    isToReformat = another.isToReformat;
    isToShortenLongNames = another.isToShortenLongNames;
    myIsInline = another.myIsInline;
    myTemplateContext = another.myTemplateContext.createCopy();
    isDeactivated = another.isDeactivated;
    for (Property property : Property.values()) {
      boolean value = another.getValue(property);
      if (value != Template.getDefaultValue(property)) {
        setValue(property, value);
      }
    }
    for (Variable variable : another.myVariables) {
      addVariable(
          variable.getName(),
          variable.getExpressionString(),
          variable.getDefaultValueString(),
          variable.isAlwaysStopAt());
    }
  }
Esempio n. 4
0
  private void showDeclaration(BeanTableSorted from, boolean isNcml) {
    Variable v = getCurrentVariable(from);
    if (v == null) return;
    infoTA.clear();
    if (isNcml) {
      Formatter out = new Formatter();
      try {
        NCdumpW.writeNcMLVariable(v, out);
      } catch (IOException e) {
        e.printStackTrace();
      }
      infoTA.appendLine(out.toString());

    } else {
      infoTA.appendLine(v.toString());
    }

    if (Debug.isSet("Xdeveloper")) {
      infoTA.appendLine("\n");
      infoTA.appendLine("FULL NAME = " + v.getFullName());
      infoTA.appendLine("\n");
      infoTA.appendLine(v.toStringDebug());
    }
    infoTA.gotoTop();
    infoWindow.setTitle("Variable Info");
    infoWindow.show();
  }
  public Float10TrajectoryObsDataset(NetcdfDataset ncd) throws IOException {
    super(ncd);

    // Get the names of the two coordinate variables and dimensions
    // and grab the variables and dimensions themselves.
    trajDimName = trajDimNameDefault;
    trajVarName = trajVarNameDefault;
    timeDimName = timeDimNameDefault;
    timeVarName = timeVarNameDefault;

    latVarName = latVarNameDefault;
    lonVarName = lonVarNameDefault;
    elevVarName = elevVarNameDefault;

    Variable latVar = ncd.getRootGroup().findVariable(latVarName);
    latVar.addAttribute(new Attribute("units", "degrees_north"));

    Variable lonVar = ncd.getRootGroup().findVariable(lonVarName);
    lonVar.addAttribute(new Attribute("units", "degrees_east"));

    this.setTrajectoryInfo(
        netcdfDataset.getRootGroup().findDimension(trajDimName),
        netcdfDataset.getRootGroup().findVariable(trajVarName),
        netcdfDataset.getRootGroup().findDimension(timeDimName),
        netcdfDataset.getRootGroup().findVariable(timeVarName),
        netcdfDataset.getRootGroup().findVariable(latVarName),
        netcdfDataset.getRootGroup().findVariable(lonVarName),
        netcdfDataset.getRootGroup().findVariable(elevVarName));
  }
Esempio n. 6
0
 public void definiteAssignment() {
   if (getOperand().isVariable()) {
     Variable v = getOperand().varDecl();
     if (v != null && v.isFinal()) {
       error("++ and -- can not be applied to final variable " + v);
     }
   }
 }
Esempio n. 7
0
    public void printTerm() {
      Iterator itr = variables.iterator();
      System.out.println("Match term -> ");

      while (itr.hasNext()) {
        Variable var = (Variable) itr.next();
        var.printVariable();
      }
    }
Esempio n. 8
0
 public static Variable freshVar(Set<Variable> vars, String sort) {
   String prefix = "?";
   int i = 0;
   Variable v = new Variable(prefix + i, sort);
   while (vars.contains(v)) {
     v.setName(prefix + (++i));
   }
   return v;
 }
Esempio n. 9
0
 public void ecrireEnregistrement(Programme prog, StringBuffer buf, int indent) {
   Divers.ecrire(buf, "function " + nom + "()" + " {", indent);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     prop.ecrirePropriete(prog, buf, indent + 1);
   }
   Divers.ecrire(buf, "}", indent);
 }
Esempio n. 10
0
 @SuppressWarnings({"unchecked", "cast"})
 public Variable fullCopy() {
   Variable res = (Variable) copy();
   for (int i = 0; i < getNumChildNoTransform(); i++) {
     ASTNode node = getChildNoTransform(i);
     if (node != null) node = node.fullCopy();
     res.setChild(node, i);
   }
   return res;
 }
Esempio n. 11
0
 /** @see jaskell.compiler.JaskellVisitor#visit(Variable) */
 public Object visit(Variable a) {
   Type ret = null;
   String vname = a.getName();
   Expression def = a.lookup(vname);
   if (def == null) // unknown symbol
   throw new CompilerException("Unknown variable " + vname);
   else ret = (Type) def.visit(this);
   a.setType(ret);
   return ret;
 }
Esempio n. 12
0
 @SuppressWarnings({"unchecked", "cast"})
 public Variable copy() {
   try {
     Variable node = (Variable) clone();
     if (children != null) node.children = (ASTNode[]) children.clone();
     return node;
   } catch (CloneNotSupportedException e) {
   }
   System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
   return null;
 }
  /**
   * Set extra information used by station obs datasets. Use stnIdVName or stnIndexVName.
   *
   * @param stnIdVName the obs variable that is used to find the station in the stnHash; may be type
   *     int or a String (char).
   * @param stnDescVName optional station var containing station description
   */
  public void setStationInfo(
      String stnIdVName, String stnDescVName, String stnIndexVName, StationHelper stationHelper) {
    this.stnIdVName = stnIdVName;
    this.stnDescVName = stnDescVName;
    this.stnIndexVName = stnIndexVName;
    this.stationHelper = stationHelper;

    if (stnIdVName != null) {
      Variable stationVar = ncfile.findVariable(stnIdVName);
      stationIdType = stationVar.getDataType();
    }
  }
  /**
   * Returns the weight of the clique that would be added to a graph if a given vertex would be
   * removed in the triangulation procedure. The return value is the number of edges in the
   * elimination clique of V that are not already present.
   */
  private int weightRequired(UndirectedGraph mdl, Variable v) {
    int rating = 1;

    for (Iterator it1 = neighborsIterator(mdl, v); it1.hasNext(); ) {
      Variable neighbor = (Variable) it1.next();
      rating *= neighbor.getNumOutcomes();
    }

    //		System.out.println(v+" = "+rating);

    return rating;
  }
 /** Insert an object into this variable at a position. */
 @Override
 public void insertAt(Variable v, Variable index) throws ScriptException {
   if (v == null) throw new ScriptException(composeMessage("Can't insert a null object"));
   if (index == null)
     configurationNode.addChild(configurationNode.getChildCount(), v.getConfigurationNodeValue());
   else {
     int indexValue = index.getIntValue();
     if (indexValue < 0 || indexValue > configurationNode.getChildCount())
       throw new ScriptException(composeMessage("Insert out of bounds: " + indexValue));
     configurationNode.addChild(indexValue, v.getConfigurationNodeValue());
   }
 }
  /**
   * Constructor.
   *
   * @param ncfile the netccdf file
   * @param typedDataVariables list of data variables; all record variables will be added to this
   *     list, except . You can remove extra
   * @param obsTimeVName observation time variable name (required)
   * @param nomTimeVName nominal time variable name (may be null)
   * @throws IllegalArgumentException if ncfile has no unlimited dimension and recDimName is null.
   */
  public RecordDatasetHelper(
      NetcdfDataset ncfile,
      String obsTimeVName,
      String nomTimeVName,
      List<VariableSimpleIF> typedDataVariables,
      String recDimName,
      Formatter errBuffer) {
    this.ncfile = ncfile;
    this.obsTimeVName = obsTimeVName;
    this.nomTimeVName = nomTimeVName;
    this.errs = errBuffer;

    // check if we already have a structure vs if we have to add it.

    if (this.ncfile.hasUnlimitedDimension()) {
      this.ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);
      this.recordVar = (StructureDS) this.ncfile.getRootGroup().findVariable("record");
      this.obsDim = ncfile.getUnlimitedDimension();

    } else {
      if (recDimName == null)
        throw new IllegalArgumentException(
            "File <"
                + this.ncfile.getLocation()
                + "> has no unlimited dimension, specify psuedo record dimension with observationDimension global attribute.");
      this.obsDim = this.ncfile.getRootGroup().findDimension(recDimName);
      this.recordVar = new StructurePseudoDS(this.ncfile, null, "record", null, obsDim);
    }

    // create member variables
    List<Variable> recordMembers = ncfile.getVariables();
    for (Variable v : recordMembers) {
      if (v == recordVar) continue;
      if (v.isScalar()) continue;
      if (v.getDimension(0) == this.obsDim) typedDataVariables.add(v);
    }

    // need the time units
    Variable timeVar = ncfile.findVariable(obsTimeVName);
    String timeUnitString =
        ncfile.findAttValueIgnoreCase(timeVar, CDM.UNITS, "seconds since 1970-01-01");
    try {
      timeUnit = new DateUnit(timeUnitString);
    } catch (Exception e) {
      if (null != errs) errs.format("Error on string = %s == %s%n", timeUnitString, e.getMessage());
      try {
        timeUnit = new DateUnit("seconds since 1970-01-01");
      } catch (Exception e1) {
        // cant happen
      }
    }
  }
 protected Expression transformVariableExpression(VariableExpression ve) {
   Variable v = ve.getAccessedVariable();
   if (v != null && v instanceof DynamicVariable) {
     Expression result = findStaticFieldOrPropAccessorImportFromModule(v.getName());
     if (result != null) {
       setSourcePosition(result, ve);
       if (inAnnotation) {
         result = transformInlineConstants(result);
       }
       return result;
     }
   }
   return ve;
 }
Esempio n. 18
0
  public void readShortMissing() throws Exception {
    Variable v = null;
    assert (null != (v = ncfileRead.findVariable("t4")));
    assert (v.getDataType() == DataType.SHORT);

    // default use of missing_value
    assert (null != (v = dsRead.findVariable("t4")));
    assert v instanceof VariableEnhanced;
    assert v instanceof VariableDS;
    VariableDS vs = (VariableDS) v;
    assert (vs.getDataType() == DataType.SHORT);

    Attribute att = vs.findAttribute(CDM.MISSING_VALUE);
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    System.out.println("missing_value = " + att.getNumericValue().shortValue());
    assert (((short) -9999) == att.getNumericValue().shortValue());
    assert (DataType.SHORT == att.getDataType());

    assert (vs.hasMissing());
    assert (vs.hasMissingValue());
    assert (vs.isMissing((double) ((short) -9999)));
    assert (vs.isMissingValue((double) ((short) -9999)));

    Array A = vs.read();
    Index ima = A.getIndex();
    int[] shape = A.getShape();
    int i, j;
    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getFloat(ima.set(i, j)) == (i * 10 + j));
      }
    }

    // turn off missing data
    vs.setMissingDataIsMissing(false);
    assert (vs.getDataType() == DataType.SHORT);

    assert (!vs.hasMissing());
    assert (vs.hasMissingValue());
    assert (!vs.isMissing((double) ((short) -9999)));
    assert (vs.isMissingValue((double) ((short) -9999)));

    vs.setMissingDataIsMissing(true);
    assert (vs.hasMissing());
    assert (vs.isMissing((double) ((short) -9999)));

    System.out.println("**************TestStandardVar Read readShortMissing");
  }
Esempio n. 19
0
  /**
   * Equality is by value.
   *
   * @param object The ConstraintIs object to compare to
   * @return <code>true</code> if object is the same as this.
   */
  public boolean equals(Object object) {
    if (object == null) return false;

    if (object == this) return true;

    // Check that the given object is the correct class
    if (!object.getClass().equals(this.getClass())) return false;

    // Check each element.
    ConstraintAssignment tmpConstraint = (ConstraintAssignment) object;

    if (!context.equals(tmpConstraint.context) || var.equals(tmpConstraint.var)) return false;

    // fudge the value comparison
    boolean exprEq = false;
    Object v1 = null;
    Object v2 = null;
    try {
      v1 = expr.getValue();
      try {
        v2 = tmpConstraint.expr.getValue();
        exprEq = v1.equals(v2);
      } catch (QueryException e2) {
      }
    } catch (QueryException e) {
      try {
        v2 = tmpConstraint.expr.getValue();
      } catch (QueryException e2) {
        exprEq = true;
      }
    }

    return exprEq;
  }
Esempio n. 20
0
 @Override
 public void compile() {
   Debugger debugContext = DinaCompiler.getDebugger();
   int variablesWithValue = 0;
   int variablesAmount = getVariablesAmount();
   for (int variableIndex = 0; variableIndex < variablesAmount; variableIndex++) {
     Variable variable = getVariable(variableIndex);
     if (variable.getValue() != null) {
       if (constructor == null) {
         constructor = new Function(ParserConstants.CONSTRUCTOR);
         constructor.setStatement(new Block());
         constructor.getStatement().setFunction(constructor);
       }
       Assignment assignment = new Assignment(variable, variable.getValue());
       constructor.getStatement().insertNode(assignment, variablesWithValue);
       variablesWithValue++;
     }
   }
   if (constructor != null) {
     Output.writeSystemInformation(Constants.BEGIN_FUNCTION);
     constructor.compile();
     if (Debugger.DEVELOPMENT_MODE) {
       debugContext.putFunction("<constructor>", constructor.getAddress());
     }
     Output.writeSystemInformation(Constants.END_FUNCTION);
   }
   int functionsAmount = functions.size();
   for (int functionIndex = 0; functionIndex < functionsAmount; functionIndex++) {
     Function function = functions.getValue(functionIndex);
     Output.writeSystemInformation(Constants.BEGIN_FUNCTION);
     function.compile();
     if (Debugger.DEVELOPMENT_MODE) {
       debugContext.putFunction(
           function.getSignatureLabel() + function.getNodeType().getSignature(),
           function.getAddress());
     }
     Output.writeSystemInformation(Constants.END_FUNCTION);
   }
   if (destructor != null) {
     Output.writeSystemInformation(Constants.BEGIN_FUNCTION);
     destructor.compile();
     if (Debugger.DEVELOPMENT_MODE) {
       debugContext.putFunction("<destructor>", destructor.getAddress());
     }
     Output.writeSystemInformation(Constants.END_FUNCTION);
   }
 }
Esempio n. 21
0
 public String toString() {
   return super.toString()
       + "(variable="
       + variable.toString()
       + ", thunk="
       + thunk.toString()
       + ")";
 }
Esempio n. 22
0
 public String toString() {
   //    return lhs + " := " + rhs + ";";
   return new StringBuilder(lhs.toString())
       .append(" := ")
       .append(rhs.toString())
       .append(";")
       .toString();
 }
Esempio n. 23
0
  public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException {
    Vgroup vgroup = (Vgroup) v2.getSPobject();

    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();

    for (int i = scanRange.first(); i <= scanRange.last(); i += scanRange.stride()) {
      Cinrad2Record[] mapScan = vgroup.map[i];
      readOneScan(mapScan, radialRange, gateRange, vgroup.datatype, ii);
    }

    return data;
  }
Esempio n. 24
0
  /* is the given variable a neighbor of this variable?*/
  public boolean isNeighbor(Variable v) {

    for (int i = 0; i < neighbors.size(); i++) {
      Variable vv = (Variable) neighbors.elementAt(i);
      if (v.equalVar(vv)) return true;
    }
    return false;
  }
 @Override
 public void setReference(Variable v) throws ScriptException {
   if (index < 0 || index >= configurationNode.getChildCount())
     throw new ScriptException(composeMessage("Index out of range: " + index));
   ConfigurationNode confNode = v.getConfigurationNodeValue();
   configurationNode.removeChild(index);
   configurationNode.addChild(index, confNode);
 }
 @Override
 public void setReference(Variable v) throws ScriptException {
   if (v == null) configurationNode.setAttribute(attributeName, null);
   else {
     String value = v.getStringValue();
     configurationNode.setAttribute(attributeName, value);
   }
 }
 /** Delete an object from this variable at a position. */
 @Override
 public void removeAt(Variable index) throws ScriptException {
   if (index == null) throw new ScriptException(composeMessage("Remove index cannot be null"));
   int indexValue = index.getIntValue();
   if (indexValue < 0 || indexValue >= configurationNode.getChildCount())
     throw new ScriptException(composeMessage("Remove index out of bounds: " + indexValue));
   configurationNode.removeChild(indexValue);
 }
 /** Get an indexed property of the variable */
 @Override
 public VariableReference getIndexed(Variable index) throws ScriptException {
   if (index == null) throw new ScriptException(composeMessage("Subscript cannot be null"));
   int indexValue = index.getIntValue();
   if (indexValue >= 0 && indexValue < configurationNode.getChildCount())
     return new NodeReference(indexValue);
   throw new ScriptException(composeMessage("Subscript is out of bounds: " + indexValue));
 }
  public static List<Variable> getVariableReferencesInScope(
      final Variable variable, final boolean includeSelf) {

    final List<Variable> variables = new ArrayList<Variable>();

    Variable variableDecl = null;
    if (!variable.isDeclaration()) {
      PsiElement psiElement = variable.resolve();
      if (psiElement instanceof Variable) {
        variableDecl = (Variable) psiElement;
      }
    } else {
      variableDecl = variable;
    }

    if (variableDecl == null) {
      return variables;
    }

    Method method = PsiTreeUtil.getParentOfType(variable, Method.class);

    PhpPsiUtil.hasReferencesInSearchScope(
        method.getUseScope(),
        variableDecl,
        new CommonProcessors.FindProcessor<PsiReference>() {
          @Override
          protected boolean accept(PsiReference psiReference) {

            PsiElement variableRef = psiReference.getElement();
            if (variableRef instanceof Variable) {
              if (includeSelf) {
                variables.add((Variable) variableRef);
              } else {
                if (!variableRef.equals(variable)) {
                  variables.add((Variable) variableRef);
                }
              }
            }

            return false;
          }
        });

    return variables;
  }
 public Array getData(Range range, String parameterName)
     throws IOException, InvalidRangeException {
   Variable variable = ncfile.getRootGroup().findVariable(parameterName);
   int varRank = variable.getRank();
   int[] varShape = variable.getShape();
   List section = new ArrayList(varRank);
   section.add(range);
   for (int i = 1; i < varRank; i++) {
     section.add(new Range(0, varShape[i] - 1));
   }
   Array array = variable.read(section);
   if (array.getShape()[0] == 1) {
     return (array.reduce(0));
   } else {
     return (array);
   }
   // return( array.getShape()[0] == 1 ? array.reduce( 0 ) : array);
 }