Esempio n. 1
0
    public void ReadFrom(Map layer) {
      sllb = Double.parseDouble(MapUtil.getValueOr(layer, "sllb", "-99"));
      slbdm = Double.parseDouble(MapUtil.getValueOr(layer, "slbdm", "-99"));
      slll = Double.parseDouble(MapUtil.getValueOr(layer, "slll", "-99"));
      sldul = Double.parseDouble(MapUtil.getValueOr(layer, "sldul", "-99"));
      slsat = Double.parseDouble(MapUtil.getValueOr(layer, "slsat", "-99"));
      sloc = Double.parseDouble(MapUtil.getValueOr(layer, "sloc", "-99"));
      slphw = Double.parseDouble(MapUtil.getValueOr(layer, "slphw", "-99"));

      airDry = slll - (slll * 0.05);
    }
Esempio n. 2
0
  public void writeFile(String filePath, Map input) {
    Velocity.init();
    VelocityContext context = new VelocityContext();

    // Weather variable.
    BucketEntry weather = MapUtil.getBucket(input, "weather").get(0);
    context.put("wst_insi", MapUtil.getValueOr(weather.getValues(), "wst_insi", "?"));

    // Soil metadata
    context.put("classification", MapUtil.getValueOr(weather.getValues(), "classification", "?"));
    context.put("soil_site", MapUtil.getValueOr(weather.getValues(), "soil_site", "?"));
    context.put("soil_name", MapUtil.getValueOr(weather.getValues(), "soil_name", "?"));
    context.put("sl_source", MapUtil.getValueOr(weather.getValues(), "sl_source", "?"));
    context.put("soil_lat", MapUtil.getValueOr(weather.getValues(), "soil_lat", "?"));
    context.put("soil_long", MapUtil.getValueOr(weather.getValues(), "soil_long", "?"));

    // Setup the soil layers.
    SoilLayer[] layers;
    BucketEntry soil = MapUtil.getBucket(input, "soil").get(0);
    ArrayList data = soil.getDataList();
    layers = new SoilLayer[data.size()];
    double cumThickness = 0.0;
    for (int i = 0; i < data.size(); i++) {
      layers[i] = new SoilLayer();
      layers[i].ReadFrom((Map) data.get(i));
      cumThickness = layers[i].calcThickness(cumThickness);
    }
    context.put("layers", layers);

    // Write template.
    Template template = Velocity.getTemplate("src\\main\\resources\\AgMIPTemplate.apsim");
    FileWriter F;
    try {

      F = new FileWriter("Test.apsim");
      template.merge(context, F);
      F.close();

    } catch (IOException ex) {
      Logger.getLogger(ApsimOutput.class.getName()).log(Level.SEVERE, null, ex);
    }
  }