Note: This page is no longer being maintained and is kept for archival purposes only.
For current information see our main page.
Garden with Insight Kurtz-Fernhout Software
Developers of custom software and educational simulations.
Home ... News ... Products ... Download ... Order ... Support ... Consulting ... Company
Garden with Insight
Product area
Help System
Contents
Quick start
Tutorial
How-to
Models

Garden with Insight v1.0 Help: Translation of EPIC Code Example


class procedure EP.PercAndLatFlowByLayer_mm( 
  numLayers: integer; layerWithDrainageSystem: integer;  
  var layers: LayerStructureArray; slopeSteepness_mPm: single;  
  returnFlowTravelTime_days: single; waterTableDepth_m: single; 
  inflowingWater_mm: single; totalRunoff_mm: single;  
  timeForDrainageSystemToReducePlantStress_days: single; 
  allowPercolation, allowLateralFlow: boolean); 
var 
  layer: integer; 
  percolationLastLayer_mm, lateralFlowThisLayer_mm,  
    percolationThisLayer_mm, swOverFCUpperLayer, swOverFCThisLayer,  
    movement_mm, proportion: single; 
begin 
{ assume this function is not called if both   
percolation and lateral flow are not allowed } 
percolationLastLayer_mm := inflowingWater_mm - totalRunoff_mm; 
if numLayers > 0 then for layer := 0 to numLayers - 1 do with layers[layer] do 
  begin 
  { add water percolated from last layer  
    (if first layer, add inflowing water - runoff) } 
  addQuantity(waterContent_mm, percolationLastLayer_mm); 
  { if water table is above the bottom of this soil layer,  
   water does not move. } 
  if (waterTableDepth_m > depth_m) then  
    begin 
    EP.PercAndLatFlowForLayer_mm( 
        layer, layerWithDrainageSystem, layers,  
        slopeSteepness_mPm, percolationThisLayer_mm, 
        lateralFlowThisLayer_mm, returnFlowTravelTime_days,  
        timeForDrainageSystemToReducePlantStress_days, 
        allowPercolation, allowLateralFlow); 
    { if percolation + lateral flow exceeds water in layer,  
      reduce both proportionally } 
    if (percolationThisLayer_mm + lateralFlowThisLayer_mm > waterContent_mm) then 
      begin 
      proportion := safediv(waterContent_mm,  
          percolationThisLayer_mm + lateralFlowThisLayer_mm); 
      if allowPercolation then  
        percolationThisLayer_mm := percolationThisLayer_mm * proportion; 
      if allowLateralFlow then  
        lateralFlowThisLayer_mm := lateralFlowThisLayer_mm * proportion; 
      end; 
    { reduce water content in layer } 
    subtractQuantity(waterContent_mm,  
        percolationThisLayer_mm + lateralFlowThisLayer_mm); 
    lateralFlow_mm := lateralFlowThisLayer_mm; 
    percolation_mm := percolationThisLayer_mm; 
    end 
  else { water table is in layer } 
    begin 
    lateralFlow_mm := 0.0; 
    percolation_mm := 0.0; 
    percolationThisLayer_mm := 0.0; 
    end; 
  percolationLastLayer_mm := percolationThisLayer_mm; 
  end; 
  { now move from the bottom to the top doing two checks:  
    if soil water > porosity and if soil water > field capacity. 
    do this only if percolation is being carried out. } 
  if allowPercolation and (numLayers > 1) then 
  for layer := numLayers - 1 downto 1 do 
    begin 
    if (layers[layer].waterContent_mm > layers[layer].porosity_mm) then 
      begin 
      movement_mm := layers[layer].waterContent_mm - layers[layer].porosity_mm; 
      addQuantity(layers[layer-1].waterContent_mm, movement_mm); 
      subtractQuantity(layers[layer-1].percolation_mm, movement_mm); 
      layers[layer].waterContent_mm := layers[layer].porosity_mm; 
      end; 
    if (layers[layer].waterContent_mm > layers[layer].fieldCapacity_mm) then 
      begin 
      swOverFCUpperLayer := safediv(layers[layer-1].waterContent_mm,  
        layers[layer-1].fieldCapacity_mm); 
      swOverFCThisLayer := safediv(layers[layer].waterContent_mm,  
        layers[layer].fieldCapacity_mm); 
      if (swOverFCUpperLayer < swOverFCThisLayer) then 
        begin 
        movement_mm := EQH.UpwardMovementOverFieldCapacityForLayer_mm( 
          layers[layer].waterContent_mm, layers[layer-1].waterContent_mm,  
          layers[layer].fieldCapacity_mm, layers[layer-1].fieldCapacity_mm); 
        addQuantity(layers[layer-1].waterContent_mm, movement_mm); 
        { can allow percolation to be negative to show upward movement } 
        layers[layer-1].percolation_mm := layers[layer-1].percolation_mm - movement_mm; 
        subtractQuantity(layers[layer].waterContent_mm, movement_mm); 
        end; 
      end; 
    end; 
  end; 

This example is part of a discussion of the translation of the EPIC code to Pascal. Compare this to the EPIC FORTRAN code example.

Home ... News ... Products ... Download ... Order ... Support ... Consulting ... Company
Updated: March 10, 1999. Questions/comments on site to webmaster@kurtz-fernhout.com.
Copyright © 1998, 1999 Paul D. Fernhout & Cynthia F. Kurtz.