;;; log.dai --- standard log files

(input file "log-std.dai")

;; We don't want an initial line just because times are not fluxes.
(defselect Year number 
  (path previous year)
  (interesting_content false))

(defselect Month number 
  (path previous month)
  (interesting_content false))

(defselect MDay number 
  (path previous mday)
  (interesting_content false))

(defselect Hour number 
  (path previous hour)
  (interesting_content false))
 
(defselect Week number 
  (path previous week)
  (interesting_content false))
 
(defselect YDay number 
  (path previous yday)
  (interesting_content false))
 
(defselect WDay number 
  (path previous wday)
  (interesting_content false))

(deflog "Total Soil Content" column
  "Information about the water, carbon and nitrogen content of the soil."
  (where "${colfid}soil_content.dlf")
  (when hourly)
  (entries (interval (path column "${column}" SoilWater Theta)
                     (spec fixed SoilWater Theta)
                     (tag "Water")
                     (dimension "mm"))
           (interval (tag "NH4")
                     (path column "${column}" Chemistry "*" trace NH4 M)
                     (spec chemical default M)
                     (dimension "kg N/ha"))
           (interval (tag "NO3")
                     (path column "${column}" Chemistry "*" trace NO3 M)
                     (spec chemical default M)
                     (dimension "kg N/ha"))
           (interval (tag "ORG_N")
                     (path column "${column}" OrganicMatter "*" total_N)
                     (spec organic default total_N)
                     (dimension "kg N/ha"))
           (interval (tag "ORG_C")
                     (path column "${column}" OrganicMatter "*" total_C)
                     (spec organic default total_C)
                     (dimension "kg C/ha"))
           (interval (tag "SOM_N")
                     (path column "${column}" OrganicMatter "*" som "*" N)
                     (spec SOM component N)
                     (dimension "kg N/ha"))
           (interval (tag "SOM_C")
                     (path column "${column}" OrganicMatter "*" som "*" C)
                     (spec SOM component C)
                     (dimension "kg C/ha"))
           (interval (tag "SMB_N")
                     (path column "${column}" OrganicMatter "*" smb "*" N)
                     (spec SMB component N)
                     (dimension "kg N/ha"))
           (interval (tag "SMB_C")
                     (path column "${column}" OrganicMatter "*" smb "*" C)
                     (spec SMB component C)
                     (dimension "kg C/ha"))
           (interval (tag "AOM_N")
                     (path column "${column}" OrganicMatter "*" am "*" om "*" N)
                     (spec AOM component N)
                     (dimension "kg N/ha"))
           (interval (tag "AOM_C")
                     (path column "${column}" OrganicMatter "*" am "*" om "*" C)
                     (spec AOM component C)
                     (dimension "kg C/ha"))
           (interval (tag "BUFFER_N")
                     (path column "${column}" OrganicMatter "*" buffer N)
                     (spec organic default buffer N)
                     (dimension "kg N/ha"))
           (interval (tag "BUFFER_C")
                     (path column "${column}" OrganicMatter "*" buffer C)
                     (spec organic default buffer C)
                     (dimension "kg C/ha"))))

(deflog "Soil N Residuals" column
  "Added N from crop residual in all numeric soil layers."
  (where "${colfid}soil_N_res.dlf")
  (when hourly)
  (entries (array (path column "${column}" residuals_N_soil)
                  (handle sum)
                  (factor 1e5)      ;g/cm^2 -> kg/ha
                  (dimension "kg N/ha/cm"))))

(deflog "Soil C Residuals" column
  "Added C from crop residual in all numeric soil layers."
  (where "${colfid}soil_C_res.dlf")
  (when hourly)
  (entries (array (path column "${column}" residuals_C_soil)
                  (handle sum)
                  (factor 1e5)      ;g/cm^2 -> kg/ha
                  (dimension "kg C/ha/cm"))))

(deflog "NO3 Root Uptake" column
  (where "${colfid}no3_uptake.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NO3 S_root)
                  (spec chemical default S_root)
                  (tag "NO3-Root")
                  (negate true)
                  (handle sum)
                  (dimension "kg N/ha/cm"))))

(deflog "NH4 Root Uptake" column
  (where "${colfid}nh4_uptake.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NH4 S_root)
                  (spec chemical default S_root)
                  (tag "NH4-Root")
                  (negate true)
                  (handle sum)
                  (dimension "kg N/ha/cm"))))

(deflog "Soil NO3 Concentration" column
  "Amount of nitrate in all numeric soil layers.
This include both the nitrogen and oxygen atoms of the nitrate."
  (where "${colfid}soil_NO3.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NO3 C)
                  (dimension "mg/l")
                  (factor 4.43e6))))     ;g NO3-N/cm³ -> mg NO3/l


(deflog "Soil NO3-N Concentration" column
  "Amount of nitrate nitrogen in all numeric soil layers.
This include only nitrogen atoms of the nitrate."
  (where "${colfid}soil_NO3-N.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NO3 C)
                  (spec chemical default C)
                  (dimension "mg/l"))))

(deflog "Soil NH4-N Concentration" column
  "Amount of dissolved ammonium nitrogen in all numeric soil layers.
This include only nitrogen atoms of the ammonium."
  (where "${colfid}soil_NH4-N_conc.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NH4 C)
                  (spec chemical default C)
                  (dimension "mg/l"))))

(deflog "Soil NH4-N Content" column
  "Total amount of ammonium nitrogen in all numeric soil layers.
This include only nitrogen atoms of the ammonium."
  (where "${colfid}soil_NH4-N_content.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NH4 M)
                  (spec chemical default M))))

(deflog "Soil Temperature" column
  "Temperature in all numeric soil layers."
  (where "${colfid}soil_temperature.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilHeat T)
                  (spec fixed SoilHeat T)
                  (dimension "dg C"))))

(deflog "Soil Water Potential" column
  "Water potential in all numeric soil layers, in cm."
  (where "${colfid}soil_water_potential.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater h)
                  (spec fixed SoilWater h)
                  (dimension "cm"))))

(deflog "Soil Water Potential (pF)" column
  "Water potential in all numeric soil layers, in pF."
  (where "${colfid}soil_water_pF.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater h)
                  (handle current)
                  (expr (min -1 [cm] x))
                  (dimension [pF])
                  (spec fixed SoilWater h))))

(deflog "Soil Water Sink" column
  "The water sink in all numeric soil layers.
The water sink is an aggregate of root uptake, preferential flow,
flow to drain pipes, and subsoil irrigation."
  (where "${colfid}soil_water_sink.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater S_sum)
                  (spec fixed SoilWater S_sum)
                  (handle sum))))

(deflog "Soil Hydraulic Conductivity (log10)" column
  (when daily)
  (where "${colfid}soil_hydraulic_conductivity.dlf")
  (entries (array (path column "${column}" SoilWater K)
                  (expr (dim (log10 x) [log10 cm/h]))
                  (spec fixed SoilWater K))))


(deflog "Soil Heat Conductivity" column
  (when daily)
  (where "${colfid}soil_heat_conductivity.dlf")
  (entries (array (path column "${column}" SoilHeat conductivity)
                  (spec fixed SoilHeat conductivity))))

(deflog "Soil Heat Capacity" column
  (when daily)
  (where "${colfid}soil_heat_capacity.dlf")
  (entries (array (path column "${column}" SoilHeat capacity)
                  (spec fixed SoilHeat capacity))))

(deflog "Soil Ice" column
  (where "${colfid}soil_ice.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater X_ice)
                  (spec fixed SoilWater X_ice))))

(deflog "Soil Ice Buffer" column
  (where "${colfid}soil_ice_buffer.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater X_ice_buffer)
                  (spec fixed SoilWater X_ice_buffer))))

(deflog "Preferential Water Flux" column
  "The preferential water flux between all numeric soil layers."
  (where "${colfid}pref_water_flux.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater q_p)
                  (spec fixed SoilWater q_p)
                  (handle sum)
                  (dimension "mm"))))

(deflog "Matrix Water Flux" column
  "The matrix water flux between all numeric soil layers."
  (where "${colfid}matrix_water_flux.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater q)
                  (spec fixed SoilWater q)
                  (handle sum)
                  (dimension "mm"))))

(deflog "Preferential Chemical Transport" chemical
  "The preferential chemical transport between all numeric soil layers."
  (where "${colfid}J_p_${chemfid}.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace
                        "${chemical}" J_tertiary)
                  (spec chemical default J_tertiary)
                  (handle sum))))

(deflog "Matrix Chemical Transport" chemical
  "The matrix chemical transport between all numeric soil layers."
  (where "${colfid}J_${chemfid}.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace
                        "${chemical}" J_matrix)
                  (spec chemical default J_matrix)
                  (handle sum))))

(deflog "Preferential NO3 Transport" column
  "The preferential nitrogen transport between all numeric soil layers."
  (where "${colfid}pref_NO3.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NO3 J_tertiary)
                  (spec chemical default J_tertiary)
                  (tag "NO3-J_tertiary")
                  (handle sum)
                  (dimension "kg N/ha"))))

(deflog "Preferential NH4 Transport" column
  "The preferential ammonium transport between all numeric soil layers."
  (where "${colfid}pref_NH4.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NH4 J_tertiary)
                  (spec chemical default J_tertiary)
                  (tag "NH4-J_tertiary")
                  (handle sum)
                  (dimension "kg N/ha"))))

(defsummary "Evapotranspiration" simple
  "Summary of evapotranspiration."
  (precision 1)
  (fetch ("Reference evapotranspiration (dry)"
          (name "Evapotranspiration, reference, dry"))
         ("Reference evapotranspiration (wet)"
          (name "Evapotranspiration, reference, wet"))
         ("Potential evapotranspiration (dry)"
          (name "Evapotranspiration, potential, dry"))
         ("Potential evapotranspiration (wet)"
          (name "Evapotranspiration, potential, wet"))
         ("Potential evapotranspiration"
          (name "Evapotranspiration, potential"))
         ("Actual Evapotranspiration"
          (name "Evapotranspiration, actual"))
         ("Potential transpiration"
          (name "Transpiration, potential"))
         ("Actual transpiration" 
          (name "Transpiration, actual"))
         ("Evaporation from snow")
         ("Evaporation from canopy")
         ("Evaporation from litter")
         ("Evaporation from ponded water")
         ("Evaporation of soil water"))
  (print_sum false))

(defsummary "Surface water balance2"
  (balance (precision 3)
           (input rain snow "Overhead irrigation" "Surface irrigation")
           (output "Matrix infiltration" "Macropore infiltration"
                   "Surface runoff"
                   "Evaporation from canopy" "Evaporation from snow"
                   "Evaporation from litter" "Evaporation from ponded water"
                   "Evaporation of soil water")
           
           (content "Interception storage" "Snow storage"
                    "Litter storage" "Surface ponding")))

(deflog "Surface Water Balance" column
  "Enough information to create a water balance for the soil surface."
  (summary "Evapotranspiration" "Surface water balance2")
  (where "${colfid}surface_water_balance.dlf")
  (when hourly)
  (entries (number (path weather "*" rain)
                   (handle sum)
                   (dimension "mm"))
           (number (path weather "*" snow)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" irrigation_overhead)
                   (tag "Overhead irrigation")
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" irrigation_surface)
                   (tag "Surface irrigation")
                  (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate default pet component
                         reference_evapotranspiration)
                   (tag "Reference evapotranspiration (dry)")
                   (handle sum)
                   (spec pet component reference_evapotranspiration))
           (number (path column "${column}" Bioclimate default pet component
                         reference_evapotranspiration_wet)
                   (tag "Reference evapotranspiration (wet)")
                   (handle sum)
                   (spec pet FAO_PM reference_evapotranspiration_wet))
           (number (path column "${column}" Bioclimate default pet component
                         wet)
                   (tag "Potential evapotranspiration (wet)")
                   (handle sum)
                   (spec pet component wet))
           (number (path column "${column}" Bioclimate default pet component
                         dry)
                   (tag "Potential evapotranspiration (dry)")
                   (handle sum)
                   (spec pet component dry))
           (number (path column "${column}" Bioclimate "*" total_ep)
                   (tag "Potential evapotranspiration")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" total_ea)
                   (tag "Actual Evapotranspiration")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" crop_ep)
                   (tag "Potential transpiration")            
                   (handle sum)
                   (spec bioclimate default crop_ep))
           (number (path column "${column}" Bioclimate "*" crop_ea)
                   (tag "Actual transpiration")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_ea)
                   (tag "Evaporation from canopy")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" snow_ea)
                   (tag "Evaporation from snow")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_ea)
                   (tag "Evaporation from litter")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" pond_ea)
                   (tag "Evaporation from ponded water")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" soil_ea)
                   (tag "Evaporation of soil water")            
                   (handle sum)
                   (dimension "mm"))
           (flux_top (path column "${column}" SoilWater q)
                     (tag "Matrix infiltration")
                     (handle sum)
                     (dimension "mm")
                     (factor -10))      ;cm -> mm
           (flux_top (path column "${column}" SoilWater q_p)
                     (tag "Macropore infiltration")
                     (handle sum)
                     (dimension "mm")
                     (factor -10))      ;cm -> mm
           (number (path column "${column}" Surface default pond)
                   (tag "Surface ponding")            
                   (dimension "mm"))
           (number (path column "${column}" Surface default runoff)
                   (tag "Surface runoff")            
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_water_storage)
                   (tag "Interception storage")            
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" Snow Ssnow)
                   (tag "Snow storage")
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_water_storage)
                   (tag "Litter storage")            
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" production_stress))))

(deflog "Denitrification" column
  "Detailed information about denitrification."
  (where "${colfid}denit.dlf")
  (summary (simple (print_sum false)
		   (fetch ("CO2 production")
			  ("CO2 production from fast pools")
			  ("Denitrification")
			  ("Denitrification from fast pools")
			  ("Redox denitrification")
			  ("Potential denitrification")
			  ("Potential denitrification from fast pools")
                          ("N2O from Nitrification"))))
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" CO2)
                     (tag "CO2 production")
                     (dimension "kg CO2-C/ha")
                     (handle sum)
                     (factor 1e5)) ;g CO2-C/cm^2 -> kg CO2/ha
           (interval (path column "${column}" OrganicMatter "*" CO2_fast)
                     (tag "CO2 production from fast pools") 
                     (dimension "kg CO2-C/ha")
                     (handle sum)
                     (factor 1e5)) ;g CO2-C/cm^2 -> kg CO2/ha
	   (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction denitrification converted)
                     (tag "Denitrification")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
	   (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction denitrification converted_fast)
                     (tag "Denitrification from fast pools")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
	   (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction denitrification converted_redox)
                     (tag "Redox denitrification")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
	   (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction denitrification potential)
                     (tag "Potential denitrification")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
	   (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction denitrification potential_fast)
                     (tag "Potential denitrification from fast pools")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
           (interval (path column "${column}" Chemistry "*"
			   combine "N" reaction nitrification N2O)
                     (handle sum)
                     (tag "N2O from Nitrification")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg N/ha
           ))

(deflog "Soil Heat Balance" column
  "All available information about the soil heat subsystem."
  (where "${colfid}soil_heat_balance.dlf")
  (when hourly)
  (entries (number (path weather "*" air_temperature)
                   (tag "T_air")
                   (spec weather weather air_temperature))
           (number (path column "${column}" Surface default T)
                   (tag "T_surface")
                   (spec surface default T)
                   (dimension "dg C"))
           (number (path column "${column}" SoilHeat T_limited)
                   (tag "T_limited")
                   (spec fixed SoilHeat T_limited))
           (index (path column "${column}" SoilHeat T)
                  (tag "T_0")
                  (index 0)
                  (dimension "dg C"))
           (index (path column "${column}" SoilHeat T)
                  (tag "T_1")
                  (index 1)
                  (dimension "dg C"))
           (index (path column "${column}" SoilHeat T)
                  (tag "T_2")
                  (index 2)
                  (dimension "dg C"))
           (index (path column "${column}" SoilHeat T_freezing)
                  (tag "T_freezing_0")
                  (index 0)
                  (dimension "dg C"))
           (index (path column "${column}" SoilHeat T_thawing)
                  (tag "T_thawing_0")
                  (index 0)
                  (dimension "dg C"))
           (index (path column "${column}" SoilHeat state)
                  (tag "state0")
                  (index 0))
           (index (path column "${column}" SoilHeat state)
                  (tag "state1")
                  (index 1))
           (index (path column "${column}" SoilHeat capacity)
                  (tag "capacity_0")
                  (index 0)
                  (spec fixed SoilHeat capacity))
           (index (path column "${column}" SoilHeat capacity_apparent)
                  (tag "C_apparent_0")
                  (index 0)
                  (spec fixed SoilHeat capacity_apparent))
           (index (path column "${column}" SoilWater Cw2)
                  (tag "Cw2_0")
                  (spec fixed SoilWater Cw2)
                  (index 0))
           (index (path column "${column}" SoilWater X_ice)
                  (tag "Ice_0")
                  (index 0)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater X_ice)
                  (tag "Ice_1")
                  (index 1)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater X_ice)
                  (tag "Ice_2")
                  (index 2)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater X_ice_buffer)
                  (tag "Ice_buffer_0")
                  (index 0)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater X_ice_buffer)
                  (tag "Ice_buffer_1")
                  (index 1)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater X_ice_buffer)
                  (tag "Ice_buffer_2")
                  (index 2)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater Theta)
                  (tag "Theta_0")
                  (index 0)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater Theta)
                  (tag "Theta_1")
                  (index 1)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater Theta)
                  (tag "Theta_2")
                  (index 2)
                  (dimension "cm^3/cm^3"))
           (index (path column "${column}" SoilWater h)
                  (tag "h_0")
                  (index 0)
                  (spec fixed SoilWater h))
           (index (path column "${column}" SoilWater h)
                  (tag "h_1")
                  (index 1)
                  (spec fixed SoilWater h))
           (index (path column "${column}" SoilWater h)
                  (tag "h_2")
                  (index 2)
                  (spec fixed SoilWater h))
           (index (path column "${column}" SoilWater S_ice)
                  (tag "S_ice_0")
                  (index 0)
                  (handle sum)
                  (spec fixed SoilWater S_ice)
                  (negate true))
           (index (path column "${column}" SoilWater S_ice)
                  (tag "S_ice_1")
                  (index 1)
                  (handle sum)
                  (spec fixed SoilWater S_ice)
                  (negate true))
           (index (path column "${column}" SoilWater S_ice)
                  (tag "S_ice_2")
                  (index 2)
                  (handle sum)
                  (spec fixed SoilWater S_ice)
                  (negate true))
           (index (path column "${column}" SoilWater q)
                  (tag "qw_0")
                  (index 0)
                  (spec fixed SoilWater q))
           (index (path column "${column}" SoilWater q)
                  (tag "qw_1")
                  (index 1)
                  (spec fixed SoilWater q))
           (index (path column "${column}" SoilWater q)
                  (tag "qw_2")
                  (index 2)
                  (spec fixed SoilWater q))
           (index (path column "${column}" SoilWater q)
                  (tag "qw_3")
                  (index 3)
                  (spec fixed SoilWater q))
           (index (path column "${column}" SoilHeat q)
                  (tag "qh_0")
                  (index 0)
                  (dimension "W/m^2")
                  (spec fixed SoilHeat q))
           (index (path column "${column}" SoilHeat q)
                  (tag "qh_1")
                  (index 1)
                  (dimension "W/m^2")
                  (spec fixed SoilHeat q))
           (index (path column "${column}" SoilHeat q)
                  (tag "qh_2")
                  (index 2)
                  (dimension "W/m^2")
                  (spec fixed SoilHeat q))
           (index (path column "${column}" SoilHeat q)
                  (tag "qh_3")
                  (index 3)
                  (dimension "W/m^2")
                  (spec fixed SoilHeat q))))

(deflog "Snow" column
  "All available information about the snow subsystem."
  (where "${colfid}snow.dlf")
  (when hourly)
  (entries (number (path column "${column}" Bioclimate "*" Snow EvapSnowPack)
                   (tag "Evaporation from snowpack")
                   (dimension "mm/h"))
           (number (path column "${column}" Bioclimate "*" Snow q_s)
                   (tag "Percolation from snowpack")
                   (dimension "mm/h"))
           (number (path column "${column}" Bioclimate "*" Snow Ssnow)
                   (tag "Snowpack content")
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" Snow Swater)
                   (tag "Snowpack liquid water content")
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" Snow age)
                   (dimension "h"))
           (number (path column "${column}" Bioclimate "*" Snow dZs)
                   (tag "Snow Depth")
                   (dimension "mm")
                   (factor 1000))))

(deflog "Surface Chemicals" chemical
  "Summary information about a specific chemical on the soil surface.
Use like (\"Surface Chemicals\" (chemical Atrazine)) to log the 
content of 'Atrazine' on the soil.  If you don't specify chemical, the 
sum of all chemicals will be logged."
  (where "${colfid}surface_chemicals.dlf")
  (declare unit String "Base unit.")
  (unit "g/ha")
  (summary (balance (description "Snow")
		    (precision 3)
                    (input snow_in)
                    (output snow_out)
                    (content snow_storage ))
	   (balance (description "Canopy")
		    (precision 3)
                    (input canopy_in canopy_transform)
                    (output canopy_harvest canopy_dissipate canopy_out)
                    (content canopy_storage))
	   (balance (description "Litter")
		    (precision 3)
                    (input litter_in litter_transform)
                    (output litter_decomposed
			    litter_leak litter_diffuse litter_tillage)
                    (content litter_storage))
	   (balance (description "Surface")
		    (precision 3)
                    (input surface_in surface_transform)
                    (output surface_decomposed
                            surface_runoff surface_out surface_mixture 
                            surface_tillage)
                    (content surface_solute surface_immobile))
	   (balance (description "All")
		    (precision 3)
                    (input spray deposit surface_transform litter_transform)
                    (output canopy_harvest canopy_dissipate
			    litter_decomposed surface_decomposed 
                            surface_runoff surface_out surface_mixture 
                            litter_tillage surface_tillage)
                    (content snow_storage canopy_storage litter_storage
                             surface_solute surface_immobile)))
  (when hourly)
  (entries (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         spray)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default spray))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         deposit)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default deposit))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         snow_in)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default snow_in))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         snow_storage)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default snow_storage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         snow_out)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default snow_out))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_in)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default canopy_in))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_storage)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default canopy_storage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_dissipate)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default canopy_dissipate))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_harvest)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default canopy_harvest))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_out)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default canopy_out))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         canopy_transform)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default canopy_transform))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_in)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_in))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_transform)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_transform))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_storage)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default litter_storage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_out)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_out))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_leak)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_leak))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_diffuse)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_diffuse))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_in)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_in))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_storage)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default surface_storage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_solute)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default surface_solute))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_immobile)
                   (handle current)
                   (dimension "${unit}")
                   (spec chemical default surface_immobile))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_out)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_out))
           (flux_top (path column "${column}" Chemistry "*" trace "${chemical}"
                           J_matrix)
		     (spec chemical default J_matrix)
                     (tag "matrix_in")
		     (negate true)
		     (handle sum)
                     (dimension "${unit}"))
           (flux_top (path column "${column}" Chemistry "*" trace "${chemical}"
                           J_tertiary)
		     (spec chemical default J_tertiary)
                     (tag "tertiary_in")
		     (negate true)
		     (handle sum)
                     (dimension "${unit}"))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_mixture)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_mixture))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_tillage)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_tillage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_tillage)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_tillage))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_runoff)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_runoff))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_transform)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_transform))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         litter_decomposed)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default litter_decomposed))
           (number (path column "${column}" Chemistry "*" trace "${chemical}"
                         surface_decomposed)
                   (handle sum)
                   (dimension "${unit}")
                   (spec chemical default surface_decomposed))))

;; We need two new log models.
(deflog "Chemical Content" chemical
  "Amount of chemicals in each numeric soil layer."
  (declare unit String "Base unit.")
  (unit "ug/m^3")
  (where "${colfid}content_${chemfid}.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*"
                        trace "${chemical}" M)
                  (handle current)
                  (dimension "${unit}")
                  (spec chemical default M))))

(deflog "Chemical Concentration" chemical
  "Concentration in water of chemicals in each numeric soil layer.  "
  (declare unit String "Base unit.")
  (unit "ng/l")
  (where "${colfid}conc_${chemfid}.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace "${chemical}" C)
                  (handle current)
                  (dimension "${unit}")
                  (spec chemical default C))))

(deflog "Chemical Content Secondary" "Chemical Content"
  "Amount of chemicals in each numeric soil layer."
  (where "${colfid}content2_${chemfid}.dlf")
  (entries (array (path column "${column}" Chemistry "*"
                        trace "${chemical}" M_secondary)
                  (handle current)
                  (dimension "${unit}")
                  (spec chemical default M_secondary))))

(deflog "Chemical Concentration Secondary" "Chemical Concentration"
  "Concentration in water of chemicals in each numeric soil layer.  "
  (where "${colfid}conc2_${chemfid}.dlf")
  (entries (array (path column "${column}" Chemistry "*" trace "${chemical}" C_secondary)
                  (handle current)
                  (dimension "${unit}")
                  (spec chemical default C_secondary))))


(deflog reaction column 
  "A log table for a specific reaction."
  (declare reaction String
	   "Name of reaction to log.  Use \"*\" to log all reactions.")
  (reaction "*"))

(deflog "Chemistry" reaction
  (where "${colfid}chemistry.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" combine "*"
                        reaction "${reaction}" S_AB)
                  (handle sum)
                  (spec reaction default S_AB))))

(deflog "Weather" column
  (where "${colfid}weather.dlf")
  (when daily)
  (entries (number (handle sum)
                   (path weather "*" precipitation)
                   (dimension "mm"))
           (number (handle sum)
                   (path weather "*" rain)
                   (dimension "mm"))
           (number (handle sum)
                   (path weather "*" snow)
                   (dimension "mm"))
           (number (handle sum)
                   (path weather "*" reference_evapotranspiration)
                   (tag "RefEvap-file")
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" 
                         pet "*" reference_evapotranspiration)
                   (tag "RefEvap-used")
                   (handle sum)
                   (dimension "mm"))
           (number (path weather "*" daily_global_radiation)
                   (dimension "W/m^2"))
           (number (path weather "*" global_radiation)
                   (tag "Mim GR")
                   (handle min)
                   (dimension "W/m^2"))
           (number (path weather "*" global_radiation)
                   (tag "Average GR")
                   (handle average)
                   (dimension "W/m^2"))
           (number (path weather "*" global_radiation)
                   (tag "Max GR")
                   (handle max)
                   (dimension "W/m^2"))
           (number (path weather "*" daily_air_temperature)
                   (dimension "dg C"))
           (number (path weather "*" daily_min_air_temperature)
                   (dimension "dg C"))
           (number (path weather "*" daily_max_air_temperature)
                   (dimension "dg C"))
           (number (path weather "*" air_temperature)
                   (tag "Avg T")
                   (handle average)
                   (dimension "dg C"))
           (number (path weather "*" air_temperature)
                   (tag "Min T")
                   (handle min)
                   (dimension "dg C"))
           (number (path weather "*" air_temperature)
                   (tag "Max T")
                   (handle max)
                   (dimension "dg C"))           ))

(deflog "Crop Photosynthesis" crop
  (where "${colfid}${cropfid}_phot.dlf")
  (when hourly)
  (entries (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NetPhotosynthesis)
		   (spec fixed Production NetPhotosynthesis)
                   (dimension "g CO2/m^2")
                   (handle sum))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod RootRespiration)
		   (spec fixed Production RootRespiration)
                   (dimension "g CO2/m^2")
                   (handle sum))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CanopyAss)
		   (spec fixed Production CanopyAss)
                   (dimension "g CH2O/m^2")
                   (handle sum))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod PotCanopyAss)
		   (spec fixed Production PotCanopyAss)
                   (dimension "g CH2O/m^2")
                   (handle sum))
           (number (path column "${column}" OrganicMatter "*" Bioincorporation CO2)
		   (spec fixed Bioincorporation CO2)
                   (tag "Bioinc_CO2")
                   (dimension "g C/m^2")
                   (handle sum)) 
           (interval (path column "${column}" OrganicMatter "*" CO2)
		     (spec organic default CO2)
                     (tag "OM_CO2")
                     ;;(dimension "g CO2/m^2")
                     (handle sum))
           ))

(deflog "Crop Production" crop
  (where "${colfid}${cropfid}_prod.dlf")
  (when (hour 12))                      ;When the stress is highest.
  (entries (number (path column "${column}" Vegetation crops crops "${crop}"
                         Devel "*" DS)
                   (dimension "none")
                   (factor 1.0))        ;Development stage [-1:2]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Devel "*" day_length)
                   (dimension "h")
                   (factor 1.0))        ;Light hours previous day.
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy Height)
                   (dimension "cm"))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy CAI)
                   (tag "Crop AI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy LeafAI)
                   (tag "Leaf AI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy StemAI)
                   (tag "Stem AI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy SOrgAI)
                   (tag "SOrg AI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root Depth)
                   (dimension "cm")
                   (factor 1.0))        ;cm [-inf:0]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WLeaf)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WDead)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WStem)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WSOrg)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WRoot)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         CrpN AccFixated)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NLeaf)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NStem)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NSOrg)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NRoot)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NDead)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root water_stress)
                   (handle max))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root water_stress_days))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         CrpN nitrogen_stress))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         CrpN nitrogen_stress_days))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Harvest cut_stress))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CLeaf)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CDead)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CStem)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CSOrg)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CRoot)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CH2OPool)
                   (dimension "Mg C/ha")
                   (factor 0.004))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod C_Loss)
                   (dimension "Mg C/ha")
                   (factor 0.01))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod AccNetPhotosynthesis)
                   (dimension "Mg CO2-C/ha")
                   (factor 0.00272727))
;           (number (path column "${column}" Vegetation crops crops "${crop}"
;                         Prod GrowthRespiration)
;                   (dimension "g CH2O/m^2")
;                      (handle sum)
;                   (factor 1.0))
;           (number (path column "${column}" Vegetation crops crops "${crop}"
;                         Prod MaintRespiration)
;                   (dimension "g CH2O/m^2")
;                      (handle sum)
;                   (factor 1.0))
;           (number (path column; "${column}" Vegetation crops crops "${crop}"
;                         Prod NetPhotosynthesis)
;                   (dimension "g CH2O/m^2")
;                      (handle sum)
;                   (factor 1.0))
           ))

(deflog "Forced LAI" crop
  (where "${colfid}${cropfid2}forced_lai.dlf")
  (when (hour 12))                      ;When the stress is highest.
  (entries (number (path column "${column}" Vegetation crops crops "${crop}"
                         Devel "*" DS)
                   (dimension "none")
                   (factor 1.0))        ;Development stage [-1:2]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy Height)
                   (dimension "cm"))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy CAI)
                   (tag "Used CAI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy SimCAI)
                   (tag "Simulated CAI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy ForcedCAI)
                   (tag "Forced CAI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod WLeaf)
                   (dimension "Mg DM/ha")
                   (factor 0.01))))

(deflog "Simple Crop Production" crop
  (where "${colfid}simple_${cropfid}_prod.dlf")
  (when (hour 12))
  (entries (number (path column "${column}"
			 Vegetation crops crops "${crop}" T_sum)
                   (dimension "dg C d")
                   (factor 1.0))        ;Temperature sum
           (number (path column "${column}"
			 Vegetation crops crops "${crop}" day)
                   (dimension "d")
                   (factor 1.0))        ;Temperature sum
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Canopy CAI)
                   (tag "Crop AI")
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root Depth)
                   (dimension "cm")
                   (factor 1.0))        ;cm [-inf:0]
           (number (path column "${column}"
			 Vegetation crops crops "${crop}" N_actual)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}"
			 Vegetation crops crops "${crop}" N_demand)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Root water_stress))))

(deflog "Old Crop Production" column
  (where "${colfid}old_crop_prod.dlf")
  (when daily)
  (entries (number (path column "${column}"
			 Vegetation crops crops "*" Phenology DS)
                   (dimension "none")
                   (factor 1.0))        ;Development stage [-1:2]
           (number (path column "${column}" Vegetation crops crops "*"
                         Phenology day_length)
                   (dimension "h")
                   (factor 1.0))        ;Light hours previous day.
           (number (path column "${column}"
			 Vegetation crops crops "*" Canopy LAI)
                   (dimension "none")
                   (factor 1.0))        ;Leaf Area Index [0:inf]
           (number (path column "${column}" Vegetation crops crops "*"
                         RootSys Depth)
                   (dimension "cm")
                   (factor 1.0))        ;cm [-inf:0]
           (number (path column "${column}"
			 Vegetation crops crops "*" Prod WLeaf)
                   (dimension "Mg DM/ha") ;Actually stem + leaf + grain
                   (factor 0.01))
           (number (path column "${column}"
			 Vegetation crops crops "*" Prod WSOrg)
                   (dimension "Mg DM/ha") ;Beet & Potatoes only
                   (factor 0.01))
           (number (path column "${column}"
			 Vegetation crops crops "*" Prod WRoot)
                   (dimension "Mg DM/ha")
                   (factor 0.01))
           (number (path column "${column}"
			 Vegetation crops crops "*" CrpAux Fixated)
                   (handle sum)
                   (accumulate true)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}"
			 Vegetation crops crops "*" Prod NCrop)
                   (dimension "kg N/ha")
                   (factor 10.0))
           ))

(deflog "Vegetation" column
  (where "${colfid}vegetation.dlf")
  (when daily)
  (entries (number (path column "${column}" Vegetation component LAI)
                   (spec vegetation component LAI))
           (number (path column "${column}" Vegetation component height)
                   (spec vegetation component height))
           (number (path column "${column}" Vegetation component cover)
                   (spec vegetation component cover))
           (number (path column "${column}" Vegetation component ACExt_PAR)
                   (spec vegetation component ACExt_PAR))
           (number (path column "${column}" Vegetation component ACRef_PAR)
                   (spec vegetation component ACRef_PAR))
           (number (path column "${column}" Vegetation component ACExt_NIR)
                   (spec vegetation component ACExt_NIR))
           (number (path column "${column}" Vegetation component ACRef_NIR)
                   (spec vegetation component ACRef_NIR))
           (number (path column "${column}" Vegetation component ARExt)
                   (spec vegetation component ARExt))
           (number (path column "${column}" Vegetation component EpFactorDry)
                   (spec vegetation component EpFactorDry))
           (number (path column "${column}" Vegetation component EpFactorWet)
                   (spec vegetation component EpFactorWet))
           (number (path column "${column}" Vegetation component albedo)
                   (spec vegetation component albedo))
           (number (path column "${column}" Vegetation component interception_capacity)
                   (spec vegetation component interception_capacity))
           (number (path column "${column}" Vegetation component shadow_stomata_conductance)
                   (spec vegetation component shadow_stomata_conductance))
           (number (path column "${column}" Vegetation component sunlit_stomata_conductance)
                   (spec vegetation component sunlit_stomata_conductance))))

(deflog "Permanent Vegetation" column
  (where "${colfid}vegetation.dlf")
  (when daily)
  (entries (number (path column "${column}" Vegetation "*" LAI)
                   (dimension "m2/m2"))
           (number (path column "${column}" Vegetation "*" N_demand)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation "*" N_actual)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation "*" N_uptake)
                   (handle sum)
                   (dimension "kg N/ha")
                   (factor 10.0))
           (number (path column "${column}" Vegetation "*" N_litter)
                   (dimension "kg N/ha")
                   (handle sum)
                   (factor 10.0))))

(deflog "Root Density" crop
  (where "${colfid}${cropfid2}rootdens.dlf")
  (when daily)
  (entries (array (tag "")
		  (path column "${column}" Vegetation crops crops "${crop}" 
                        Root Density)
                  (spec fixed RootSystem Density))))

(deflog "Root form parameter" crop
  (where "${colfid}${cropfid2}rootform.dlf")
  (when daily)
  (entries (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Prod WRoot)
                   (spec fixed Production WRoot))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Phenology DS)
                   (spec phenology default DS))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Root Depth)
                   (spec fixed RootSystem Depth))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Root rootdens "*" a)
                   (spec rootdens GP1D a))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Root rootdens "*" L0)
                   (spec rootdens GP1D L0))
           (number (path column "${column}" Vegetation crops crops "${crop}" 
                         Root rootdens "*" k)
                   (spec rootdens GP1D k))
	   (content (path column "${column}" Vegetation crops crops "${crop}" 
			  Root Density)
		    (spec fixed RootSystem Density)
		    (tag "10 cm")
		    (height -10 [cm]))
	   (content (path column "${column}" Vegetation crops crops "${crop}" 
			  Root Density)
		    (spec fixed RootSystem Density)
		    (tag "50 cm")
		    (height -50 [cm]))
	   (interval (path column "${column}" Vegetation crops crops "${crop}" 
			   Root Density)
		     (spec fixed RootSystem Density)
		     (tag "0-1 m")
		     (from  0 [cm])
		     (to -100 [cm]))))

(deflog "Bioclimate" column
  (where "${colfid}bioclimate.dlf")
  (when hourly)
  (entries (number (path weather "*" daily_air_temperature)
                   (dimension "dg C"))
           (number (path weather "*" air_temperature)
                   (dimension "dg C"))
           (number (path weather "*" global_radiation)
                   (dimension "W/m2"))
           (number (path weather "*" daily_global_radiation)
                   (dimension "W/m2"))
           (number (path column "${column}" Bioclimate "*" 
                         pet "*" reference_evapotranspiration)
                   (handle sum)
                   (dimension "mm"))
           (number (path weather "*" rain)
                   (handle sum)
                   (dimension "mm"))
           (number (path weather "*" snow)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate default albedo)
                   (handle average)
                   (spec bioclimate default albedo))
           (number (path column "${column}" Bioclimate "*" total_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" total_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" irrigation_overhead)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         irrigation_overhead_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" irrigation_surface)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         irrigation_surface_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" canopy_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_water_storage)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         canopy_water_storage_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" canopy_water_in)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_water_out)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_water_storage)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         litter_water_storage_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" litter_water_in)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" litter_water_out)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" canopy_water_bypass)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" snow_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" snow_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" snow_water_in)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" Snow Ssnow)
                   (tag "snow_water_storage")
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         snow_water_in_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" snow_water_out)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         snow_water_out_temperature)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" pond_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" pond_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" pond_water_in)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Surface default pond)
                   (tag "pond_water_storage")
                   (dimension "mm"))
           (number (path column "${column}" Surface default runoff)
                   (tag "pond_water_runoff")
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*"
                         pond_water_in_temperature)
                   (dimension "dg C"))
           (flux_top (path column "${column}" SoilWater q)
                     (tag "soil_water_in")
                     (handle sum)
                     (dimension "mm")
                     (factor -10))      ;cm -> mm
           (number (path column "${column}" Bioclimate "*" soil_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" soil_ea)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" crop_ep)
                   (handle sum)
                   (dimension "mm"))
           (number (path column "${column}" Bioclimate "*" crop_ea)
                   (handle sum)
                   (dimension "mm"))))

(deflog "PMSW" column
  (where "${colfid}pmsw.tab")
  (when hourly)
  (print_dimension false)
  (print_tags false)
  (entries (number (path column "${column}" Bioclimate "*" svat PMSW netrad_brunt)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_a)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_astab)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_aa)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_aastab1)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_aastab2)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_as)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_ac)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tskin)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tcan)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tleaf)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW e_c)
                   (dimension "Pa"))
           (number (path column "${column}" Bioclimate "*" svat PMSW e_sl)
                   (dimension "Pa"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tskin_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tcan_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW tleaf_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW e_c_star)
                   (dimension "Pa"))
           (number (path column "${column}" Bioclimate "*" svat PMSW e_sl_star)
                   (dimension "Pa"))
           (number (path column "${column}" Bioclimate "*" svat PMSW ha)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW hl)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW hs)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW lea)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW lel)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW ha_star)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW hl_star)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW hs_star)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW lea_star)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW lel_star)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW gflux)
                   (dimension "W/m**2"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtcta)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtltc)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtstc)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtcta_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtltc_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW dtstc_star)
                   (dimension "dg C"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_1)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_2)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_3)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_4)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_temp)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_def)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_theta)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW f_etep)
                   (dimension "NA"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_sc_1)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_sc_2)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_sc_js)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_sc_min)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW r_sc_star)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW rcmin_star)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW pstress)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW ustar_raa)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW ustar_raastab1)
                   (dimension "s/m"))
           (number (path column "${column}" Bioclimate "*" svat PMSW ustar_raastab2)
                   (dimension "s/m"))))

(deflog "SSOC" column
  "Information related to the sun/shade open canopy SVAT model."
  (declare T_unit String "Temperature unit.")
  (T_unit "dg C")
  (declare g_unit String "Conductivity unit.")
  (g_unit "m/s")
  (declare e_unit String "Pressure.")
  (e_unit "Pa")
  (declare R_unit String "Radiation.")
  (R_unit "W/m^2")
  (declare E_unit String "Water flux.")
  (E_unit "mm/h")
  (where "${colfid}svat_SSOC.dlf")
  (when hourly)
  (entries (number (tag T_air)
                   (path weather weather air_temperature)
                   (spec weather weather air_temperature)
                   (dimension "${T_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC T_s)
                   (spec svat SSOC T_s)
                   (dimension "${T_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC T_0)
                   (spec svat SSOC T_0)
                   (dimension "${T_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC T_c)
                   (spec svat SSOC T_c)
                   (dimension "${T_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC T_sun)
                   (spec svat SSOC T_sun)
                   (dimension "${T_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC T_shadow)
                   (spec svat SSOC T_shadow)
                   (dimension "${T_unit}")
                   (handle current))
           (number (tag gs_sun)
                   (path column "${column}" Vegetation component 
                         sunlit_stomata_conductance)
                   (spec vegetation component sunlit_stomata_conductance)
                   (dimension "${g_unit}")
                   (handle current))
           (number (tag gs_shadow)
                   (path column "${column}" Vegetation component 
                         shadow_stomata_conductance)
                   (spec vegetation component shadow_stomata_conductance)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC g_a)
                   (spec svat SSOC g_a)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC g_H_s_c)
                   (spec svat SSOC g_H_s_c)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC g_H_sun_c)
                   (spec svat SSOC g_H_sun_c)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC gb_W_sun)
                   (spec svat SSOC gb_W_sun)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC g_W_sun_c)
                   (spec svat SSOC g_W_sun_c)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC
                         g_H_shadow_c)
                   (spec svat SSOC g_H_shadow_c)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC 
                         gb_W_shadow)
                   (spec svat SSOC gb_W_shadow)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC 
                         g_W_shadow_c)
                   (spec svat SSOC g_W_shadow_c)
                   (dimension "${g_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC e_a  )
                   (spec svat SSOC e_a  )
                   (dimension "${e_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC e_c)
                   (spec svat SSOC e_c)
                   (dimension "${e_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC e_sat_air)
                   (spec svat SSOC e_sat_air)
                   (dimension "${e_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC s)
                   (spec svat SSOC s)
                  ;; (dimension "${e_unit}")
                   (handle current))
           (number (path column "${column}" Bioclimate "*" svat SSOC R_abs_soil)
                   (spec svat SSOC R_abs_soil)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC
                         R_abs_shadow)
                   (spec svat SSOC R_abs_shadow)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC R_abs_sun)
                   (spec svat SSOC R_abs_sun)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC H_soil)
                   (spec svat SSOC H_soil)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC H_sun)
                   (spec svat SSOC H_sun)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC H_shadow)
                   (spec svat SSOC H_shadow)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC H_c_a)
                   (spec svat SSOC H_c_a)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC LE_sun)
                   (spec svat SSOC LE_sun)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC LE_shadow)
                   (spec svat SSOC LE_shadow)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC LE_atm)
                   (spec svat SSOC LE_atm)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC E_trans)
                   (spec svat SSOC E_trans)
                   (dimension "${E_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC R_eq_abs_soil)
                   (spec svat SSOC R_eq_abs_soil)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC R_eq_abs_sun)
                   (spec svat SSOC R_eq_abs_sun)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC R_eq_abs_shadow)
                   (spec svat SSOC R_eq_abs_shadow)
                   (dimension "${R_unit}")
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC LAI)
                   (spec svat SSOC LAI)
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC 
                         sun_LAI_fraction_total)
                   (spec svat SSOC sun_LAI_fraction_total)
                   (handle average))
           (number (path column "${column}" Bioclimate "*" svat SSOC cover)
                   (spec svat SSOC cover)
                   (handle average))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_W_sun_c)
                   (spec svat SSOC G_W_sun_c)
                   (handle average))
          (number (path column "${column}" Bioclimate "*" svat SSOC rho_a)
                   (spec svat SSOC rho_a)
                   (handle average))
          (number (path column "${column}" Bioclimate "*" svat SSOC gamma)
                   (spec svat SSOC gamma)
                   (handle average))
          (number (path column "${column}" Bioclimate "*" svat SSOC lambda)
                  (spec svat SSOC lambda)
                  (handle average))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_R_soil)
                  (spec svat SSOC G_R_soil)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_R_sun)
                  (spec svat SSOC G_R_sun)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_R_shadow)
                  (spec svat SSOC G_R_shadow)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_R_leaf)
                  (spec svat SSOC G_R_leaf)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC G_H_a)
                  (spec svat SSOC G_H_a)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC k_h)
                  (spec svat SSOC k_h)
                  (handle current))
          (number (path column "${column}" Bioclimate "*" svat SSOC T_z0)
                  (spec svat SSOC T_z0)
                  (handle current)
		  (dimension "${T_unit}"))
          (number (path column "${column}" Bioclimate "*" svat SSOC E_soil)
                  (spec svat SSOC E_soil)
                  (handle average)
		  (dimension "${E_unit}")
		  )
	  (number (path column "${column}" Bioclimate default
			outgoing_Short_radiation)
		  (spec bioclimate default outgoing_Short_radiation)
		  (handle average)
		  (dimension "${R_unit}"))
	  (number (path column "${column}" Bioclimate default
			incoming_PAR_radiation)
		  (spec bioclimate default incoming_PAR_radiation)
		  (handle average)
		  (dimension "${R_unit}"))
	  (number (path column "${column}" Bioclimate default
			incoming_NIR_radiation)
		  (spec bioclimate default incoming_NIR_radiation)
		  (handle average)
		  (dimension "${R_unit}"))
	  (number (path weather "*" global_radiation)
		  (spec weather weather global_radiation)
		  (handle average)
		  (dimension "${R_unit}"))
	  (number (path column "${column}" Bioclimate "*" svat SSOC R_soil)
		  (spec svat SSOC R_soil)
		  (dimension "${R_unit}")
		  (handle average))
	  (number (path column "${column}" Bioclimate "*" svat SSOC R_sun)
		  (spec svat SSOC R_sun)
		  (dimension "${R_unit}")
		  (handle average))
	  (number (path column "${column}" Bioclimate "*" svat SSOC R_shadow)
		  (spec svat SSOC R_shadow)
		  (dimension "${R_unit}")
		  (handle average))
	  (number (path column "${column}" Bioclimate "*" svat SSOC R_total)
		  (spec svat SSOC R_total)
		  (dimension "${R_unit}")
		  (handle average))
	  (number (path column "${column}" Bioclimate "*" svat_failed)
		  (spec bioclimate default svat_failed))))

(deflog "Groundwater" column
  (where "${colfid}groundwater.dlf")
  (when hourly)
  (entries (number (path column "${column}" Groundwater component height)
		   (description "Aquifer pressure table.")
                   (tag "table")
                   (dimension "cm"))
	   (number (path column "${column}" SoilWater table_low)
                   (spec fixed SoilWater table_low)
                   (dimension "cm"))
	   (number (path column "${column}" SoilWater table_high)
                   (spec fixed SoilWater table_high)
                   (dimension "cm"))
           (number (path column "${column}" Groundwater aquitard h_aquifer)
                   (dimension "cm"))
           (flux_bottom (tag "Percolation")
			(documentation "\
This is the amount of water leaving the system through the soil bottom.
It can be negative if there is cabilary rise.")
                        (path column "${column}" SoilWater q)
                        (spec fixed SoilWater q)
                        (handle sum)
                        (negate true)
                        (dimension "mm"))
           (number (path column "${column}" Drain lateral DrainFlow)
                   (handle sum)
                   (dimension "mm")
                   (factor 10))))

(deflog Bioincorporation column
  (where "${colfid}bioincorporation.dlf")
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" am 
                           "bio/incorporation" om "*" N)
                     (tag "SOIL_N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am 
                           "bio/incorporation" om "*" C) 
                     (tag "SOIL_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "*" om "*" top_N)
                   (tag "TOP_N")
                   (dimension "kg N/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "*" om "*" top_C)
                   (tag "TOP_C")
                   (dimension "kg C/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation
                         N_removed)
                   (tag "REMOVED_N")
                   (handle sum)
                   (dimension "kg N/ha")
                   (factor 10))         ;g/m^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation 
                         C_removed)
                   (tag "REMOVED_C")
                   (handle sum)
                   (dimension "kg C/ha")
                   (factor 10))         ;g/m^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation CO2)
                   (tag "CO2")
                   (handle sum)
                   (dimension "kg C/ha")
                   (factor 10))         ;g/m^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" Bioincorporation 
                           N_added)
                     (tag "ADDED_N")
                     (handle sum)
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" Bioincorporation 
                           C_added)
                     (tag "ADDED_C")
                     (handle sum)
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation speed)
                   (tag "Speed")
                   (handle sum)
                   (dimension "kg DM/ha")
                   (factor 4.2))        ;g DM/m^2 -> kg C/ha
           ))

(deflog aom column
  "A log table for a specific AOM."
  (declare aom String
	   "Name of added organic matter to log.
Use \"*\" to log all added organic matter matter.")
  (aom "*"))

(deflog AOM aom
  "Log content of specific added organic matter, such as fertilizer."
  (where "${colfid}aom.dlf")
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" am "${aom}" om "*" N)
                     (tag "SOIL_N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om "*" C) 
                     (tag "SOIL_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om "*" top_N)
                   (tag "TOP_N")
                   (dimension "kg N/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om "*" top_C)
                   (tag "TOP_C")
                   (dimension "kg C/ha")
                   (factor 1e5))))      ;g/cm^2 -> kg/ha

(deflog "AOM Pools" aom
  "Log content of all pools in specific added organic matter."
  (where "${colfid}aom-pools.dlf")
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-SLOW N)
                     (tag "SOIL1-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-SLOW C) 
                     (tag "SOIL1-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-SLOW top_N)
                   (tag "TOP1-N")
                   (dimension "kg N/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-SLOW top_C)
                   (tag "TOP1-C")
                   (dimension "kg C/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-FAST N)
                     (tag "SOIL2-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-FAST C) 
                     (tag "SOIL2-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-FAST top_N)
                   (tag "TOP2-N")
                   (dimension "kg N/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-FAST top_C)
                   (tag "TOP2-C")
                   (dimension "kg C/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-DIRECT N)
                     (tag "SOIL3-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-DIRECT C) 
                     (tag "SOIL3-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-DIRECT top_N)
                   (tag "TOP3-N")
                   (dimension "kg N/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" am "${aom}" om AOM-DIRECT top_C)
                   (tag "TOP3-C")
                   (dimension "kg C/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           ))

(deflog "Organic Matter" column
  "Information about all organic matter pools."
  (where "${colfid}organic-matter.dlf")
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" som SOM-SLOW N)
                     (tag "SOM1-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som SOM-SLOW C)
                     (tag "SOM1-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som SOM-FAST N)
                     (tag "SOM2-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som SOM-FAST C)
                     (tag "SOM2-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som SOM-INERT N)
                     (tag "SOM3-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som SOM-INERT C)
                     (tag "SOM3-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" smb SMB-SLOW N)
                     (tag "SMB1-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" smb SMB-SLOW C)
                     (tag "SMB1-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" smb SMB-FAST N)
                     (tag "SMB2-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" smb SMB-FAST C)
                     (tag "SMB2-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-SLOW N)
                     (tag "AOM1-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-SLOW C)
                     (tag "AOM1-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-FAST N)
                     (tag "AOM2-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-FAST C)
                     (tag "AOM2-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-DIRECT N)
                     (tag "AOM3-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om AOM-DIRECT C)
                     (tag "AOM3-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" buffer N)
                     (tag "BUFFER-N")
                     (dimension "kg N/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" buffer C)
                     (tag "BUFFER-C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           ))

(deflog "DOM Pools" column
  "Information about Disolved Organic Matter pools."
  (where "${colfid}dom.dlf")
  (when hourly)
  (entries (interval (path column "${column}" OrganicMatter "*" dom "0" N M)
                     (tag "D1-N")
                     (spec fixed DOM-Element M)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" N S)
                     (tag "D1-N-S-sum")
                     (spec fixed DOM-Element S)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" N S_p)
                     (tag "D1-N-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" N S_drain)
                     (tag "D1-N-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "0" N J_matrix)
                     (tag "D1-N-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "0" N J_tertiary)
                     (tag "D1-N-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "0" N J_matrix)
                        (tag "D1-N-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
                        (dimension "kg N/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "0" N J_tertiary)
                        (tag "D1-N-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
                        (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" C M)
                     (tag "D1-C")
                     (spec fixed DOM-Element M)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" C S)
                     (tag "D1-C-S-sum")
                     (spec fixed DOM-Element S)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" C S_p)
                     (tag "D1-C-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "0" C S_drain)
                     (tag "D1-C-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "0" C J_matrix)
                     (tag "D1-C-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "0" C J_tertiary)
                     (tag "D1-C-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "0" C J_matrix)
                        (tag "D1-C-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
                        (dimension "kg C/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "0" C J_tertiary)
                        (tag "D1-C-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
                        (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" N M)
                     (tag "D2-N")
                     (spec fixed DOM-Element M)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" N S)
                     (tag "D2-N-S-sum")
                     (spec fixed DOM-Element S)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" N S_p)
                     (tag "D2-N-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" N S_drain)
                     (tag "D2-N-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "1" N J_matrix)
                     (tag "D2-N-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "1" N J_tertiary)
                     (tag "D2-N-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "1" N J_matrix)
                        (tag "D2-N-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
                        (dimension "kg N/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "1" N J_tertiary)
                        (tag "D2-N-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
                        (dimension "kg N/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" C M)
                     (tag "D2-C")
                     (spec fixed DOM-Element M)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" C S)
                     (tag "D2-C-S-sum")
                     (spec fixed DOM-Element S)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" C S_p)
                     (tag "D2-C-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" dom "1" C S_drain)
                     (tag "D2-C-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "1" C J_matrix)
                     (tag "D2-C-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}" OrganicMatter "*" dom "1" C J_tertiary)
                     (tag "D2-C-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "1" C J_matrix)
                        (tag "D2-C-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
                        (dimension "kg C/ha"))
           (flux_bottom (path column "${column}" OrganicMatter "*" dom "1" C J_tertiary)
                        (tag "D2-C-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
                        (dimension "kg C/ha"))
           ))

(deflog pool column
  "A log table for a specific organic matter pool."
  (declare pool String
	   "Name of pool to log.  Use \"*\" to log all pools.")
  (pool "*"))

(defsummary "DOM Pool N Balance"  balance
  (precision 3)
  (input "N-J-mat-in" "N-J-pref-in" "N-S-SOM")
  (output "N-J-mat-out" "N-J-pref-out" "N-S-drain")
  (content N))

(defsummary "DOM Pool C Balance"  balance
  (precision 3)
  (input "C-J-mat-in" "C-J-pref-in" "C-S-SOM")
  (output "C-J-mat-out" "C-J-pref-out" "C-S-drain")
  (content C))

(deflog "DOM Pool" pool
  "Information about a Disolved Organic Matter pool."
  (where "${colfid}dom-pool.dlf")
  (summary "DOM Pool N Balance" "DOM Pool C Balance")
  (when hourly)
  (entries (interval (path column "${column}" 
			   OrganicMatter "*" dom "${pool}" N M)
                     (tag "N")
                     (spec fixed DOM-Element M)
                     (dimension "kg N/ha"))
           (interval (path column "${column}" 
			   OrganicMatter "*" dom "${pool}" N S)
                     (tag "N-S-sum")
                     (spec fixed DOM-Element S)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" N S_p)
                     (tag "N-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" N S_drain)
                     (tag "N-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg N/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" domsorp "*" S_N)
                     (tag "N-S-SOM")
                     (spec domsorp default S_N)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}"
			   OrganicMatter "*" dom "${pool}" N J_matrix)
                     (tag "N-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_top (path column "${column}"
			   OrganicMatter "*" dom "${pool}" N J_tertiary)
                     (tag "N-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg N/ha"))
           (flux_bottom (path column "${column}"
			      OrganicMatter "*" dom "${pool}" N J_matrix)
                        (tag "N-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
			(negate true)
                        (dimension "kg N/ha"))
           (flux_bottom (path column "${column}"
			      OrganicMatter "*" dom "${pool}" N J_tertiary)
                        (tag "N-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
			(negate true)
                        (dimension "kg N/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C M)
                     (tag "C")
                     (spec fixed DOM-Element M)
                     (dimension "kg C/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C S)
                     (tag "C-S-sum")
                     (spec fixed DOM-Element S)
		     (negate true)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C S_p)
                     (tag "C-S-pref")
                     (spec fixed DOM-Element S_p)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C S_drain)
                     (tag "C-S-drain")
                     (spec fixed DOM-Element S_drain)
                     (handle sum)
                     (dimension "kg C/ha"))
           (interval (path column "${column}"
			   OrganicMatter "*" domsorp "*" S_C)
                     (tag "C-S-SOM")
                     (spec domsorp default S_C)
                     (handle sum)
		     (negate true)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C J_matrix)
                     (tag "C-J-mat-in")
                     (spec fixed DOM-Element J_matrix)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_top (path column "${column}"
			   OrganicMatter "*" dom "${pool}" C J_tertiary)
                     (tag "C-J-pref-in")
                     (spec fixed DOM-Element J_tertiary)
                     (handle sum)
                     (dimension "kg C/ha"))
           (flux_bottom (path column "${column}"
			      OrganicMatter "*" dom "${pool}" C J_matrix)
                        (tag "C-J-mat-out")
                        (spec fixed DOM-Element J_matrix)
                        (handle sum)
			(negate true)
                        (dimension "kg C/ha"))
           (flux_bottom (path column "${column}"
			      OrganicMatter "*" dom "${pool}" C J_tertiary)
                        (tag "C-J-pref-out")
                        (spec fixed DOM-Element J_tertiary)
                        (handle sum)
			(negate true)
                        (dimension "kg C/ha"))
           ))

(deflog "DOM-N" pool
  "Information about nitrogen in disolved organic matter pools."
  (where "${colfid}dom-N.dlf")
  (when hourly)
  (entries (array (path column "${column}" OrganicMatter "*" dom "${pool}" N M)
                  (tag "N")
                  (spec fixed DOM-Element M))))

(deflog "DOM-C" pool
  "Information about carbon in disolved organic matter pools."
  (where "${colfid}dom-C.dlf")
  (when hourly)
  (entries (array (path column "${column}" OrganicMatter "*" dom "${pool}" C M)
                  (tag "C")
                  (spec fixed DOM-Element M))))

(deflog "Drain Sink Water" column
  (where "${colfid}drain_sink_water.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater S_drain)
		  (spec fixed SoilWater S_drain)
                  (handle sum))))

(deflog "Biopore Drain Sink Water" column
  (where "${colfid}biopore_drain_sink_water.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater S_p_drain)
		  (spec fixed SoilWater S_p_drain)
                  (handle sum))))

(deflog "Drain Sink NO3" column
  (where "${colfid}drain_sink_NO3.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NO3 S_soil_drain)
		  (spec chemical default S_soil_drain)
                  (handle sum)
		  (negate true))))

(deflog "Drain Sink NH4" column
  (where "${colfid}drain_sink_NH4.dlf")
  (when hourly)
  (entries (array (path column "${column}" Chemistry "*" trace NH4 S_soil_drain)
		     (spec chemical default S_soil_drain)
                  (handle sum)
		  (negate true))))

(deflog "Soil Water Content" column
  (where "${colfid}soil_water_content.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater Theta)
                  (handle current)
                  (spec fixed SoilWater Theta))))

(deflog "Fertilizer" column
  "Track applied fertilizer."
  (where "${colfid}fertilizer_monthly.dlf")
  (when monthly)
  (entries (number (path column "${column}" Chemistry "*" trace NO3 spray)
		   (spec chemical default spray)
                   (handle sum)
                   (tag "Surface-NO3"))
           (interval (path column "${column}"
			   Chemistry "*" trace NO3 S_external)
		     (spec chemical default S_external)
		     (handle sum)
		     (tag "Surface-NO3"))
           (number (path column "${column}" Chemistry "*" trace NH4 spray)
		   (spec chemical default spray)
                   (handle sum)
                   (tag "Surface-NH4"))
           (interval (path column "${column}"
			   Chemistry "*" trace NH4 S_external)
		     (spec chemical default S_external)
		     (handle sum)
		     (tag "Soil NH4"))
           (number (path column "${column}" OrganicMatter "*" fertilized_N)
                   (handle sum)
                   (tag "Org_N")
                   (factor 1e5)         ;g/cm^2 -> kg/ha
                   (dimension "kg N/ha"))
           (number (path column "${column}" OrganicMatter "*" fertilized_C)
                   (handle sum)
                   (tag "Org_C")
                   (factor 1e5)         ;g/cm^2 -> kg/ha
                   (dimension "kg C/ha"))
           (number (path column "${column}" applied_DM)
                   (handle sum)
                   (tag "WetWeight")
                   (dimension "ton ww/ha"))
           (number (path column "${column}" first_year_utilization)
                   (handle sum)
                   (tag "1stYear")
                   (dimension "kg N/ha"))
           (number (path column "${column}" second_year_utilization)
                   (tag "2ndYear")
                   (dimension "kg N/ha"))
           (number (path column "${column}" Chemistry "*" trace NH4
			 canopy_dissipate)
                   (spec chemical default canopy_dissipate)
                   (handle sum)
                   (tag "NH4-Volatilization")
                   (dimension "kg N/ha"))))

(deflog "Fertilizer Yearly" "Fertilizer"
  (where "${colfid}fertilizer_yearly.dlf")
  (when (and (month 3)
             (mday 31)
             (hour 23))))

(defsummary "Crop Carbon Balance" simple
  "Carbon balance for the crops.

Warning: This balance is not finished.

Note that negative deltas means the amount increases."
  (precision 3)
  (fetch (Seed_C  (name "Seed"))
         (CLeaf (name "Leaves") (factor -1))
         (CDead (name "Dead leaves still on crop") (factor -1))
         (CStem (name "Stem") (factor -1))
         (CSOrg (name "Storage organ") (factor -1))
         (CRoot (name "Roots") (factor -1))
         (CH2OPool (name "Assimilate") (factor -1))
         ;; (C_Loss (name "Lost leaves and roots") (factor -1))
         (NetPhotosynthesis (name "Netto photosynthesis"))
         ;;(GrowthRespiration (name "Crop growth respiration") (factor -1))
         ;;(MaintRespiration (name "Crop maintenance respiration")(factor -1))
         (Harvest_C (name "Removed by harvest") (factor -1))
         ("Residuals_C_root" (name "Root residuals") (factor -1))
         ("Residuals_C_top" (name "Surface residuals") (factor -1)))
  (sum_name "Balance"))

(defsummary "Litter Carbon Balance" simple
  "Carbon balance for the litter system.

Note that negative deltas means the amount of carbon increases."
  (precision 3)
  (fetch ("Residuals_C_top" (name "Surface residuals"))
         ("Bioinc_C-Surface" (name "Bioincorporated from surface") (factor -1))
         ("Fertilizer_C" (name "Fertilization"))
         (tillage_C_top (name "Removed from surface by tillage"))
         (Surface_C (name "Litter") (factor -1)))
  (sum_name "Balance"))

(defsummary "Soil Carbon Balance" simple
  "Carbon balance for the soil.

Note that negative deltas means the amount of carbon increases."
  (precision 3)
  (fetch ("Bioinc_C-Soil" (name "Bioincorporated to soil"))
         ("Residuals_C_soil" (name "Dead roots added to soil"))
         (tillage_C_soil (name "Added to soil by tillage"))
         ("SMB-CO2-total" (name "Soil biomass respiration") (factor -1))
         (Soil_C (name "Soil content") (factor -1)))
  (sum_name "Balance"))

(defsummary "Total Carbon Balance" simple
  "Carbon balance for the complete system.

Warning: This balance is not finished.

Note that negative deltas means the amount of carbon increases."
  (precision 3)
  (fetch (Soil_C (name "Soil content") (factor -1))
         (Surface_C (name "Litter") (factor -1))
         ("SMB-CO2-total" (name "Soil biomass respiration") (factor -1))
         ("Bioinc_C-Surface" (name "Bioincorporated from surface") (factor -1))
         ("Bioinc_C-Soil" (name "Bioincorporated to soil"))
         ;; ("Bioinc_CO2" (name "Bioincorporation respiration") (factor -1))
         (Seed_C (name "Seed"))
         (CLeaf (name "Leaves") (factor -1))
         (CDead (name "Dead leaves still on crop") (factor -1))
         (CStem (name "Stem") (factor -1))
         (CSOrg (name "Storage organ") (factor -1))
         (CRoot (name "Roots") (factor -1))
         (CH2OPool (name "Assimilate") (factor -1))
         (NetPhotosynthesis (name "Netto photosynthesis"))
         ;;(GrowthRespiration (name "Crop growth respiration") (factor -1))
         ;;(MaintRespiration (name "Crop maintenance respiration") (factor -1))
         (Harvest_C (name "Removed by harvest") (factor -1))
         ("Residuals_C_root" (name "Dead roots lost by crop") (factor -1))
         ("Residuals_C_soil" (name "Dead roots added to soil"))
         ("Fertilizer_C" (name "Fertilization"))
         (tillage_C_top (name "Removed from surface by tillage"))
         (tillage_C_soil (name "Added to soil by tillage")))
  (sum_name "Balance"))

(defsummary "C Input" simple
  "This summary provides the information needed by the OrganicMatter init
submodel.  The amount printed under 'Total C Input' corresponds to the
'input' parameter, and the amount under 'Roots' corresponds to the
'root' parameter."
  (fetch ("Fertilizer_C" (name "Fertilizer"))
         ("Residuals_C_top" (name "Residuals"))
         ("Residuals_C_root" (name "Roots"))
         ("Bioinc_CO2" (factor -1.0)))
  (sum_name "Total C input")
  (period "y")
  (precision 0))

(deflog "Carbon Balance" crop
  (where "${colfid}${cropfid2}C_Bal.dlf")
  (when hourly)
  (summary "Total Carbon Balance" "Crop Carbon Balance" 
           "Litter Carbon Balance" "Soil Carbon Balance" "C Input")
  (entries (interval (path column "${column}" OrganicMatter "*" total_C)
                     (tag "Soil_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" som "*" C)
                     (tag "SOM_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" smb "*" C)
                     (tag "SMB_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" am "*" om "*" C)
                     (tag "AOM_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" buffer C)
                     (tag "BUFFER_C")
                     (dimension "kg C/ha")
                     (factor 1e5))      ;g/cm^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" CO2)
                     (tag "SMB-CO2-total") 
                     (dimension "kg C/ha")
                     (handle sum)
                     (factor 1e5)) ;g CO2-C/cm^2 -> kg CO2-C/ha
           (number (path column "${column}" OrganicMatter "*" am "*" om "*" top_C)
                   (tag "Surface_C")
                   (dimension "kg C/ha")
                   (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation
                         C_removed)
                   (tag "Bioinc_C-Surface")
                   (handle sum)
                   (dimension "kg C/ha")
                   (factor 10))         ;g/m^2 -> kg/ha
           (interval (path column "${column}" OrganicMatter "*" Bioincorporation
                           C_added)
                     (tag "Bioinc_C-Soil")
                     (handle sum)
                     (dimension "kg C/ha")
                     (factor 1e5))        ;g/cm^2 -> kg/ha
           (number (path column "${column}" OrganicMatter "*" Bioincorporation CO2)
                   (tag "Bioinc_CO2")
                       (handle sum)
                   (dimension "kg C/ha")
                   (factor 10))         ;g/m^2 -> kg/ha
           (number (path column "${column}" seed_C)
                   (handle sum)
                   (tag "Seed_C")
                   (dimension "kg C/ha"))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CLeaf)
                   (dimension "kg C/ha")
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CDead)
                   (dimension "kg C/ha")
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CStem)
                   (dimension "kg C/ha")
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CSOrg)
                   (dimension "kg C/ha")
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CRoot)
                   (dimension "kg C/ha")
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod CH2OPool)
                   (dimension "kg C/ha")
                   (factor 4))          ;g CH2O/m^2 -> kg C/ha
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod C_Loss)
                   (dimension "kg C/ha")
                   (handle sum)
                   (factor 10))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod NetPhotosynthesis)
                   (dimension "kg C/ha")
                   (handle sum)
                   (factor 2.727272727))        ;g CO2/m^2 -> kg C/ha
           (number (path column "${column}" OrganicMatter "*" fertilized_C)
                   (handle sum)
                   (tag "Fertilizer_C")
                   (factor 1e5)         ;g/cm^2 -> kg/ha
                   (dimension "kg C/ha"))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod GrowthRespiration)
                   (dimension "kg C/ha")
                   (handle sum)
                   (factor 4))        ;g CH2O/m^2 -> kg C/ha
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         Prod MaintRespiration)
                   (dimension "kg C/ha")
                   (handle sum)
                   (factor 4))        ;g CH2O/m^2 -> kg C/ha
           (number (path column "${column}" harvest_C)
                   (handle sum)
                   (tag "Harvest_C")
                   (factor 10); g/m^2 -> kg/ha
                   (dimension "kg C/ha"))
           (number (path column "${column}" residuals_C_top)
                   (handle sum)
                   (tag "Residuals_C_top")
                   (factor 10); g/m^2 -> kg/ha
                   (dimension "kg C/ha"))
           (number (path column "${column}" residuals_C_root)
                   (handle sum)
                   (tag "Residuals_C_root")
                   (factor 10); g/m^2 -> kg/ha
                   (dimension "kg C/ha"))
           (interval (path column "${column}" residuals_C_soil)
                     (handle sum)
                     (tag "Residuals_C_soil")
                     (factor 1e5)      ;g/cm^2 -> kg/ha
                     (dimension "kg C/ha"))
           (number (path column "${column}" OrganicMatter "*" tillage_C_top)
                   (handle sum)
                   (factor 10); g/m^2 -> kg/ha
                   (dimension "kg C/ha"))
           (interval (path column "${column}" OrganicMatter "*" tillage_C_soil)
                     (handle sum)
                     (factor 1e5)      ;g/cm^2 -> kg/ha
                     (dimension "kg C/ha"))
           ))

(deflog "Tertiary biopores water" biopore
  "State of water in the tertiary biopores model.
The log is only valid if you have any 'matrix' biopores, as the 'drain' 
contains no water."
  (where "${colfid}tertiary-water-${bioporefid}.dlf")
  (when hourly)
  (biopore matrix)
  (entries (number (path column "${column}" Movement "*" 
                         Tertiary biopores water_volume)
                   (handle current)
                   (spec tertiary biopores water_volume))
           (number (path column "${column}" Movement "*" 
                         Tertiary biopores water_height)
                   (handle current)
                   (spec tertiary biopores water_height))
           (number (path column "${column}" Movement "*" 
                         Tertiary biopores ddt)
                   (handle min)
                   (spec tertiary biopores ddt))
           (number (path column "${column}" Movement "*" 
                         Tertiary biopores classes "${biopore}" iterations)
                   (handle max)
                   (spec biopore matrix iterations))
           (array (path column "${column}" Movement "*" 
                        Tertiary biopores classes "${biopore}" h_bottom)
                  (handle max)
                  (spec biopore matrix h_bottom))
           (array (path column "${column}" Movement "*" 
                        Tertiary biopores classes "${biopore}" h3_soil)
                  (handle max)
                  (spec biopore matrix h3_soil))))

(deflog "Matrix to biopores" column
  "Water moving from the soil matrix to the biopores, excluding drain."
  (where "${colfid}M2B-water.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater S_M2B)
                  (spec fixed SoilWater S_M2B)
                  (handle sum))))

(deflog "Biopores to matrix" column
  "Tertiary water sink term."
  (where "${colfid}B2M-water.dlf")
  (when hourly)
  (entries (array (path column "${column}" SoilWater S_B2M)
                  (spec fixed SoilWater S_B2M)
                  (handle sum))))

(defsummary "Surface water" balance
  "Above ground water balance."
  (precision 1)
  (require_top true)
  (input "Precipitation" "Overhead irrigation" "Surface irrigation" "Tillage")
  (output "Snow evaporation" "Canopy evaporation" "Litter evaporation" 
          "Pond evaporation" "Soil evaporation"
	  "Matrix infiltration" "Tertiary infiltration"
          "Runoff")
  (content Snow Canopy Litter Pond))

(defsummary "Snow water" balance
  "Snow water balance."
  (precision 1)
  (require_top true)
  (input "Precipitation" "Overhead irrigation" "Pond to snow")
  (output "Snow evaporation" "Snow out")
  (content Snow))

(defsummary "Canopy water" balance
  "Canopy water balance."
  (precision 1)
  (require_top true)
  (input "Snow out")
  (output "Canopy evaporation" "Canopy bypass" "Canopy out")
  (content "Canopy"))

(defsummary "Litter water" balance
  "Litter water balance."
  (precision 1)
  (require_top true)
  (input "Canopy bypass" "Canopy out" "Surface irrigation" "Tillage"
	 "Litter pond up" "Litter soil up")
  (output "Litter evaporation" "Litter bypass" "Litter wash off" "Litter out")
  (content "Litter"))

(defsummary "Ponded water" balance
  "Pond (surface) water balance."
  (precision 1)
  (require_top true)
  (input "Litter bypass" "Litter wash off" "Litter out")
  (output "Pond evaporation" "Soil evaporation" "Matrix infiltration"
	  "Tertiary infiltration" "Runoff" "Litter pond up" "Litter soil up"
	  "Pond to snow")
  (content "Pond"))

(deflog "Surface water" column
  "Information about above ground water."
  (where "${colfid}surface_water.dlf")
  (when hourly)
  (summary "Surface water" "Snow water" "Canopy water" "Litter water"
	   "Ponded water")
  (entries (number (tag "Precipitation")
		   (documentation "\
Amount of water entering the system as rain and snow.")
                   (path weather weather precipitation)
                   (spec weather weather precipitation)
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Overhead irrigation")
		   (documentation "\
Amount of water added by overhead irrigation.")
                   (path column "${column}" Bioclimate "*" irrigation_overhead)
                   (spec bioclimate default irrigation_surface)
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Surface irrigation")
		   (documentation "\
Amount of water added by surface irrigation.")
                   (path column "${column}" Bioclimate "*" irrigation_surface)
                   (spec bioclimate default irrigation_surface)
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Tillage")
		   (documentation "\
Amount of soil water added by tillage operations.")
                   (path column "${column}" Bioclimate "*" tillage_water)
                   (spec bioclimate default tillage_water)
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Snow evaporation")
		   (documentation "\
Amount of water removed from snowpack by evaporation.")
                   (path column "${column}" Bioclimate "*" snow_ea)
                   (spec bioclimate default snow_ea)            
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Canopy evaporation")
		   (documentation "\
Amount of intercepted water removed by evaporation.")
                   (path column "${column}" Bioclimate "*" canopy_ea)
                   (spec bioclimate default canopy_ea)            
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter evaporation")
		   (documentation "\
Amount of water removed from the litter by evaporation.")
                   (path column "${column}" Bioclimate "*" litter_ea)
                   (spec bioclimate default litter_ea)            
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Surface evaporation")
		   (documentation "\
Amount of water removed from the pond and soil surface by evaporation.
Also include water entering litter from soil and pond.")
                   (path column "${column}" Surface default EvapSoilSurface)
                   (spec surface default EvapSoilSurface)            
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Pond evaporation")
		   (documentation "\
Amount of water removed from the pond by evaporation.")
                   (path column "${column}" Bioclimate "*" pond_ea)
                   (spec bioclimate default pond_ea)            
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Soil evaporation")
		   (documentation "\
Amount of water removed from the soil by evaporation.")
                   (path column "${column}" Bioclimate "*" soil_ea)
                   (spec bioclimate default soil_ea)            
                   (handle sum)
                   (dimension "mm"))
           (flux_top (tag "Matrix infiltration")
                     (documentation "\
Amount of water entering the soil through the matrix system.

This is the normal infiltration channel.")
                     (path column "${column}" SoilWater q)
                     (spec fixed SoilWater q)
                     (handle sum)
                     (negate true)
                     (dimension "mm"))
           (flux_top (tag "Tertiary infiltration")
                     (documentation "\
Amount of water leaving the surface through the biopores.")
                     (path column "${column}" SoilWater q_p)
                     (spec fixed SoilWater q_p)
                     (handle sum)
                     (negate true)
                     (dimension "mm"))
           (number (tag "Runoff")
		   (documentation "\
Amount of water running of the surface.

This is intended to simulate water runoff from a surface with a slop.
However, since Daisy is a one dimensional model, the water have
nowhere go to.  For typical setups, this value will be zero.")
                   (path column "${column}" Surface default runoff)
                   (spec surface default runoff)
                   (handle sum)
                   (dimension "mm"))
           (number (tag "Snow")
		   (documentation "Total water stored in the snowpack.")
                   (path column "${column}" Bioclimate "*"  Snow Ssnow)
                   (spec fixed Snow Ssnow)
                   (dimension "mm"))
           (number (tag "Canopy cover")
                   (path column "${column}"
                         Bioclimate "*" canopy_cover) 
                   (spec bioclimate default canopy_cover))
           (number (tag "Canopy capacity")
		   (documentation "Interception capacity of the canopy.")
                   (path column "${column}"
                         Bioclimate "*" canopy_water_capacity) 
                   (spec bioclimate default canopy_water_capacity)
                   (dimension "mm"))
           (number (tag "Canopy")
		   (documentation "Intercepted water stored on the canopy.")
                   (path column "${column}"
                         Bioclimate "*" canopy_water_storage) 
                   (spec bioclimate default canopy_water_storage)
                   (dimension "mm"))
	   (number (tag "Litter cover")
		   (path column "${column}" Litter component cover)
		   (spec litter component cover))
           (number (tag "Litter capacity")
		   (documentation "Water carrying  Inapacity of the litter.")
                   (path column "${column}"
                         Bioclimate "*" litter_water_capacity) 
                   (spec bioclimate default litter_water_capacity)
                   (dimension "mm"))
           (number (tag "Litter")
		   (documentation "Water stored in the litter.")
                   (path column "${column}"
                         Bioclimate "*" litter_water_storage) 
                   (spec bioclimate default litter_water_storage)
                   (dimension "mm"))
           (number (tag "Pond")
		   (documentation "Total amount of ponded water.")
                   (path column "${column}" Surface default pond) 
                   (spec surface default pond)
                   (dimension "mm"))
           (number (tag "Snow out")
		   (documentation "Water leaving snow pack")
                   (path column "${column}"
			 Bioclimate "*" snow_water_out) 
                   (spec bioclimate default snow_water_out)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Pond to snow")
		   (documentation "Water leaving pond for snow pack")
                   (path column "${column}"
			 Bioclimate "*" pond_water_to_snow) 
                   (spec bioclimate default pond_water_to_snow)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Canopy out")
		   (documentation "Water dripping off canopy")
                   (path column "${column}"
			 Bioclimate "*" canopy_water_out) 
                   (spec bioclimate default canopy_water_out)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Canopy bypass")
		   (documentation "Water bypassing canopy")
                   (path column "${column}"
			 Bioclimate "*" canopy_water_bypass) 
                   (spec bioclimate default canopy_water_bypass)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter out")
		   (documentation "Water leaving litter storage downwards.\n\
This can include overflow and Darcy flow.")
                   (path column "${column}"
			 Bioclimate "*" litter_water_out) 
                   (spec bioclimate default litter_water_out)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter bypass")
		   (documentation "Water bypassing litter")
                   (path column "${column}"
			 Bioclimate "*" litter_water_bypass) 
                   (spec bioclimate default litter_water_bypass)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter wash off")
		   (documentation "Water hitting litter without entering.")
                   (path column "${column}"
			 Bioclimate "*" litter_wash_off) 
                   (spec bioclimate default litter_wash_off)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter pond up")
		   (documentation "Water entering litter from pond.")
                   (path column "${column}"
			 Bioclimate "*" litter_pond_up) 
                   (spec bioclimate default litter_pond_up)
		   (handle sum)
                   (dimension "mm"))
           (number (tag "Litter soil up")
		   (documentation "Water entering litter from soil.")
                   (path column "${column}"
			 Bioclimate "*" litter_soil_up) 
                   (spec bioclimate default litter_soil_up)
		   (handle sum)
                   (dimension "mm"))))

(defsummary "Colloids balance" balance
  "Balance for colloids released from the soil surface by rain."
  (precision 3)
  (require_top true)
  (input Generate)
  (output Filter Biopore-Drain Soil-Drain Matrix-Leak Biopore-Leak)
  (content Surface Soil Biopores Error))

(defsummary "Colloids pool balance" balance
  "Balance for pool of readily available colloids."
  (precision 3)
  (input Avail-Gain)
  (output Avail-Loss)
  (content Avail-Surface))

(deflog "Colloids" column
  "Colloid generation and trace."
  (where "${colfid}colloids.dlf")
  (summary "Colloids pool balance" "Colloids balance")
  (declare unit String "Base unit.")
  (unit "g/m^2")
  (when hourly)
  (entries (number (tag "Generate")
                   (path column "${column}" Chemistry "*" trace colloid
                         surface_transform)
                   (spec chemical default surface_transform)
                   (dimension "${unit}")
                   (handle sum))
           (number (tag "Surface")
                   (path column "${column}" Chemistry "*" trace colloid
                         surface_storage)
                   (spec chemical default surface_storage)
                   (dimension "${unit}")
                   (handle current))
           (interval (tag "Soil-Intra")
                     (path column "${column}" Chemistry "*" trace colloid 
                           M_primary)
                     (dimension "${unit}")
                     (spec chemical default M_primary))
           (interval (tag "Soil")
                     (path column "${column}" Chemistry "*" trace colloid M)
                     (dimension "${unit}")
                     (spec chemical default M))
           (interval (tag "Biopores")
                     (path column "${column}" Chemistry "*"
			   trace colloid M_tertiary)
                     (dimension "${unit}")
                     (spec chemical default M_tertiary))
           (interval (tag "Filter")
                     (path column "${column}" Chemistry "*" trace 
                           colloid S_transform)
                     (spec chemical default S_transform)
                     (dimension "${unit}")
                     (negate true)
                     (handle sum))
           (interval (tag "Soil-Drain")
                     (path column "${column}" Chemistry "*"
			   trace colloid S_soil_drain)
                     (spec chemical default S_soil_drain)
                     (dimension "${unit}")
                     (handle sum)
                     (negate true))
           (interval (tag "Biopore-Drain")
                     (path column "${column}" Chemistry "*" 
			   trace colloid S_p_drain)
                     (spec chemical default S_p_drain)
                     (dimension "${unit}")
                     (handle sum))
           (flux_bottom (tag "Matrix-Leak")
                        (path column "${column}" Chemistry "*" trace collodid
                              J_matrix)
                        (spec chemical default J_matrix)
                        (dimension "${unit}")
                        (handle sum)
                        (negate true))
           (flux_bottom (tag "Biopore-Leak")
                        (path column "${column}" Chemistry "*" trace collodid
                              J_tertiary)
                        (spec chemical default J_tertiary)
                        (dimension "${unit}")
                        (handle sum)
                        (negate true))
           (interval (path column "${column}" Chemistry "*" trace colloid
                           M_error)
                     (tag "Error")
                     (dimension "${unit}")
                     (spec chemical default M_error))
           (number (tag "R")
                   (path column "${column}" Bioclimate default direct_rain)
                   (spec bioclimate default direct_rain)
                   (handle sum))
           (number (tag "Energy")
                   (path column "${column}" Chemistry multi
                         combine colloids reaction colgen_Jarvis99 E)
                   (spec reaction colgen_Jarvis99 E)
                   (handle current))
           (number (tag "Avail-Soil")
                   (path column "${column}" Chemistry multi
                         combine colloids reaction colgen_Jarvis99 Ms)
                   (spec reaction colgen_Jarvis99 Ms)
                   (handle current))
	   (number (tag "Avail-Surface")
                   (path column "${column}" Chemistry multi
                         combine colloids reaction colgen_Jarvis99 As)
                   (spec reaction colgen_Jarvis99 As)
                   (dimension "${unit}")
                   (handle current))
	   (number (tag "Avail-Loss")
                   (path column "${column}" Chemistry multi
                         combine colloids reaction colgen_Jarvis99 D)
                   (spec reaction colgen_Jarvis99 D)
                   (dimension "${unit}")
                   (handle sum))
	   (number (tag "Avail-Gain")
                   (path column "${column}" Chemistry multi
                         combine colloids reaction colgen_Jarvis99 P)
                   (spec reaction colgen_Jarvis99 P)
                   (dimension "${unit}")
                   (handle sum))))

(deflog Failure column
  "Keep track of when our transport models fail."
  (where "${colfid}failure.dlf")
  (when hourly)
  (entries (number (tag "Water")
                   (path column "${column}" Movement "*" water_failure_level)
                   (spec movement vertical water_failure_level)
                   (handle max))
           (number (tag "Solute")
                   (path column "${column}" Movement "*" solute_failure_level)
                   (spec movement vertical solute_failure_level)
                   (handle max))))

(deflog LeafPhot crop
  "Select a fraction and layer for leaf photosynthesis."
  (declare fraction String
	   "Leaf fraction to log.  Either 'LeafPhot', 'sunlit', or 'reserved'.
If the light distribution model distinguish between sunlit and show leaves,
the 'LeafPhot' will give you shadow leaves.  Otherwise, 'LeafPhot' will 
cover all non-reserved leaves, and 'sunlit' will be empty.  The 'reserved'
fraction will always give you leaves reserved to this crop in a multi-crop 
system, and never distinguish between sunlit and shadow leaves.")
  (fraction "LeafPhot")
  (declare layer Integer
           "Layer to log.  Layer 0 is the top of the vegetation.
The bottom of the vegetation is the value of the 'NoOfIntervals' 
parameter in the 'default' bioclimate model.  By default, 30."))

(deflog Stomatacon LeafPhot
  "Stomata conductivity related state."
  (where "${cropfid2}sc-${fraction}-${layer}.dlf")
  (when hourly)
  (entries (index (path column "${column}" Vegetation crops crops "${crop}"
                        "${fraction}" "*" LAI_vector)
                  (index $layer)
                  (spec photosynthesis Farquhar LAI_vector)
                  (handle current))
           (index (path column "${column}" Vegetation crops crops "${crop}"
                        "${fraction}" "*" gs_vector)
                  (index $layer)
                  (spec photosynthesis Farquhar gs_vector)
                  (handle current))
           (index (path column "${column}" Vegetation crops crops "${crop}"
                        "${fraction}" "*" hs_vector)
                  (index $layer)
                  (spec photosynthesis Farquhar hs_vector)
                  (handle current))
           (index (path column "${column}" Vegetation crops crops "${crop}"
                        "${fraction}" "*" pn_vector)
                  (index $layer)
                  (spec photosynthesis Farquhar pn_vector)
                  (handle current))
           (index (path column "${column}" Vegetation crops crops "${crop}"
                        "${fraction}" "*" cs_vector)
                  (index $layer)
                  (spec photosynthesis Farquhar cs_vector)
                  (handle current))
           (number (dimension "ng/cm^3")
		   (path column "${column}" 
			 Vegetation crops crops "${crop}" Root ABAConc)
		   (spec fixed RootSystem ABAConc)
                   (handle current))
           (number (path column "${column}" 
			 Vegetation crops crops "${crop}" Root h_x)
		   (spec fixed RootSystem h_x)
                   (handle current))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         "${fraction}" "*" ABA_effect)
                   (spec photosynthesis Farquhar ABA_effect)
                   (handle current))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         "${fraction}" "*" Gamma)
                   (spec photosynthesis Farquhar Gamma)
                   (handle current))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         "${fraction}" "*" gbw)
                   (spec photosynthesis Farquhar gbw)
                   (handle current))
           (number (path column "${column}" Vegetation crops crops "${crop}"
                         "${fraction}" "*" Ass)
                   (spec photosynthesis Farquhar Ass)
                   (handle sum))))

(deflog "Time" column
  "Keep track of time."
  (where "time.dlf")
  (summary (simple (fetch (Used) (SoilWater))))
  (when true)
  (entries (number (path dt)
                   (tag "Used")
                   (handle average)
                   (spec program Daisy dt))
           (number (path column "${column}" SoilWater dt)
                   (tag "SoilWater")
                   (handle average)
                   (spec fixed SoilWater dt))
           (number (path column "${column}" SoilWater sink_cell)
                   (tag "SW Cell")
                   (handle average)
                   (spec fixed SoilWater sink_cell))
           (number (tag "NO3")
                   (path column "${column}" Chemistry multi trace NO3 dt)
                   (spec chemical default dt))
           (number (tag "NO3 Cell")
                   (path column "${column}" Chemistry multi trace NO3 sink_cell)
                   (spec chemical default sink_cell))
           ))

(deflog "Drain lateral" column
  "Keep track of lateral drains."
  (where "drain_lateral.dlf")
  (when true)
  (entries (number (path column "${column}" Drain lateral pipe_level)
                   (spec drain lateral pipe_level)
                   (handle current))
           (number (path column "${column}" Drain lateral height)
                   (spec drain lateral height)
                   (handle current))
           (number (path column "${column}" Drain lateral DrainFlow)
                   (spec drain lateral DrainFlow)
                   (handle sum))
           (number (path column "${column}" Drain lateral EqDrnFlow)
                   (spec drain lateral EqDrnFlow)
                   (handle sum))
           (volume (path column "${column}" Drain lateral S)
                   (spec drain lateral S)
                   (handle sum))))

(deflog biopore-chemical chemical
  "Log chemicals in biopores."
  (declare biopore String
	   "Name of biopore to log.")
  (biopore "*")
  ;; Add it to the log files.
  (parameter_names &old biopore)
  ;; Use chemical name as part of file name.
  (declare bioporefid string
           "File name component indicating biopore logged.")
  (bioporefid (cond ((string-equal "${biopore}" "*")
		"biopore")
	       (true
		"${biopore}"))))
  
(defsummary "Biopore content" balance
  (precision 3)
  (input "From matrix"
	 "From above")
  (output "To below" "To drain")
  (content "Content"))

(deflog "Biopore chemical" biopore-chemical
  (declare unit String "Base unit.")
  (unit "g/ha")
  (where "${colfid}tertiary-${bioporefid}-${chemfid}.dlf")
  (when hourly)
  (summary "Biopore content")
  (entries (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}"
			   M "${chemical}" value)
		     (handle current)
		     (tag "Content")
		     (dimension "${unit}")
		     (spec biopore matrix M value))
	   (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}"
			   S_chem "${chemical}" value)
		     (handle sum)
		     (tag "From matrix")
		     (dimension "${unit}")
		     (spec biopore matrix S_chem value))
	   (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}"
			   S_chem_to_drain "${chemical}" value)
		     (handle sum)
		     (tag "To drain")
		     (dimension "${unit}")
		     (spec biopore drain S_chem_to_drain value))
           (flux_top (tag "From above")
                     (path column "${column}"  Movement "*"
			   Tertiary biopores classes "${biopore}"
			   J "${chemical}" value)
		     (dimension "${unit}")
                     (spec biopore matrix J value)
                     (handle sum)
                     (negate true))
           (flux_bottom (tag "To below")
			(path column "${column}"  Movement "*"
			      Tertiary biopores classes "${biopore}"
			      J "${chemical}" value)
			(dimension "${unit}")
			(spec biopore matrix J value)
			(handle sum)
			(negate true))
	   ))

(deflog "Biopore water" biopore
  (declare unit String "Base unit.")
  (unit "mm")
  (where "${colfid}tertiary-${bioporefid}-water.dlf")
  (when hourly)
  (summary "Biopore content")
  (entries (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}" Theta)
		     (handle current)
		     (tag "Content")
		     (dimension "${unit}")
		     (spec biopore matrix Theta))
	   (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}"
			   S)
		     (handle sum)
		     (tag "From matrix")
		     (dimension "${unit}")
		     (spec biopore matrix S))
	   (interval (path column "${column}" Movement "*"
			   Tertiary biopores classes "${biopore}"
			   S_to_drain)
		     (handle sum)
		     (tag "To drain")
		     (dimension "${unit}")
		     (spec biopore drain S_to_drain))
           (flux_top (tag "From above")
                     (path column "${column}"  Movement "*"
			   Tertiary biopores classes "${biopore}"
			   q)
                     (dimension "${unit}")
                     (spec biopore component q)
		     (handle sum)
                     (negate true))
           (flux_bottom (tag "To below")
			(path column "${column}"  Movement "*"
			      Tertiary biopores classes "${biopore}"
			      q)
			(dimension "${unit}")
			(spec biopore component q)
			(handle sum)
			(negate true))
	   ))

(deflog "M2B" biopore
  (where "${colfid}B2M-${bioporefid}.dlf")
  (when true)
  (entries (array (path column "${column}" Movement "*"
                        Tertiary biopores classes "${biopore}"
                        B2M)
                  (handle sum)
                  (spec biopore component B2M))))

(deflog "B2M" biopore
  (where "${colfid}M2B-${bioporefid}.dlf")
  (when true)
  (entries (array (path column "${column}" Movement "*"
                        Tertiary biopores classes "${biopore}"
                        M2B)
                  (handle sum)
                  (spec biopore component M2B))))

(deflog "Crop uptake" crop
  (where "${colfid}${cropfid}-uptake.dlf")
  (declare unit String "Base unit.")
  (unit "kg N/ha")
  (when daily)
  (entries (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root H2OUpt)
		   (handle sum)
		   (dimension "mm")
                   (spec fixed RootSystem H2OUpt))
	   (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root NH4Upt)
		   (handle sum)
		   (dimension "${unit}")
                   (spec fixed RootSystem NO3Upt))
	   (number (path column "${column}" Vegetation crops crops "${crop}"
                         Root NO3Upt)
		   (handle sum)
		   (dimension "${unit}")
                   (spec fixed RootSystem NH4Upt))
	   (interval (path column "${column}" Vegetation crops crops "${crop}"
			   Root H2OExtraction)
		     (handle sum)
		     (dimension "mm")
		     (spec fixed RootSystem H2OExtraction))
	   (interval (path column "${column}" Vegetation crops crops "${crop}"
			   Root NH4Extraction)
		     (handle sum)
		     (dimension "${unit}")
		     (spec fixed RootSystem NH4Extraction))
	   (interval (path column "${column}" Vegetation crops crops "${crop}"
			   Root NO3Extraction)
		     (handle sum)
		     (dimension "${unit}")
		     (spec fixed RootSystem NO3Extraction))))

;;; log.dai ends here
