public void UpdateSiteHydrology(EcoregionDateData data, ref ushort Water, ref ushort SnowPack)
        {
            Water -= (ushort)Math.Max(Water - FieldCap[ecoregion], 0);

            snowmelt = Math.Min(SnowPack, data.Maxmonthlysnowmelt);

            SnowPack += (ushort)(data.Newsnow - snowmelt);

            WaterIn = data.Precin + snowmelt;//mm

            float PrecLoss = WaterIn * ecoregion.PrecLossFrac();

            float infiltration = WaterIn - PrecLoss;

            Water += (ushort)infiltration;

            // Leakage
            Leakage = Math.Max(ecoregion.LeakageFrac() * (Water - FieldCap[ecoregion]), 0);
            Water -= (ushort)Leakage;

            // Instantaneous runoff (excess of porosity)
            RunOff = Math.Max(Water - Porosity[ecoregion] * ecoregion.RootingDepth(), 0);
            Water -= (ushort)RunOff;
        }
        public float FoliageSenescence(EcoregionDateData monthdata)
        {
            // If it is fall
            ushort Litter = (ushort)(species.TOfol() * Fol);
            Fol -= Litter;

            if( IsAlive) IsAlive =NSCfrac > 0.01F;

            return Litter;
        }
        public float SubtractInterception(EcoregionDateData data, float LAIsum, ref ushort Water)
        {
            Interception = data.Precin * Calculate_Interception_Fraction(LAIsum);

            Water -= (ushort)Interception;

            return Interception;
        }
        public void ComputePhotosynthesis(ref float IncomingRadiation, int PressureHead, EcoregionDateData data, ref ushort Water)
        {
            if (LayerIndex == 0)
            {
                cohort.MaintenanceRespiration = (ushort) Math.Min(cohort.NSC, data.FTempRespMaintResp[cohort.species] * (cohort.Root + cohort.Wood));//gC //IMAXinverse
                cohort.NSC -=  cohort.MaintenanceRespiration;
            }

            LAI = cohort.Fol / (cohort.species.SLWmax() / (1 / (float)PlugIn.IMAX) - cohort.species.SLWDel() * (float)LayerIndex * (1 / (float)PlugIn.IMAX) * cohort.Fol);

            Radiation = (ushort)(IncomingRadiation * (float)Math.Exp(-cohort.species.K() * LAI));

            Frad = CumputeFrad(Radiation, cohort.species.HalfSat());

            Fwater = GetFWater(cohort.species, PressureHead);

            NetPsn = Fwater * Frad * cohort.Fage() * data.FTempPSNRefNetPsn[cohort.species] * cohort.Fol * (1 / (float)PlugIn.IMAX);

            cohort.NSC += NetPsn;

            FolResp = Fwater * data.FTempRespDayRefResp[cohort.species] * cohort.Fol * (1 / (float)PlugIn.IMAX);

            float GrossPsn = NetPsn + FolResp;

            if (GrossPsn > 0)
            {
                Transpiration = (GrossPsn * Constants.MCO2_MC) / data.WUE_CO2_corr[cohort.species];

                if (Transpiration>0) Hydrology.SubtractTranspiration((ushort)Transpiration, ref Water);
            }

            if (data.Leaf_On[cohort.Species])
            {
                //float IdealFol = (cohort.species.FracFol() * cohort.FActiveBiom * cohort.MaxBiomass);
                float IdealFol = (cohort.species.FracFol() * cohort.FActiveBiom() * cohort.Biomass);

                if (IdealFol > cohort.Fol)
                {
                    float Folalloc = Math.Max(0, Math.Min(cohort.NSC, cohort.species.CFracBiomass() * IdealFol - cohort.Fol)); // gC/mo

                    if (Folalloc > 0) cohort.Fol += (ushort)(Folalloc / cohort.species.CFracBiomass());// gDW

                    cohort.NSC -= (ushort)Folalloc;
                }

                //if (sl.LayerIndex == sl.cohort.NrOfSublayers-1)
                //{
                float rootpluswoodalloc = Math.Max(cohort.NSC - (cohort.species.DNSC() * cohort.FActiveBiom() * (cohort.Biomass + cohort.Root)), 0);//gC

                if (rootpluswoodalloc > 0)
                {
                    cohort.NSC -= (ushort)rootpluswoodalloc;

                    float RootAlloc = Math.Min(rootpluswoodalloc, cohort.species.CFracBiomass() * Math.Max(0, (cohort.species.FracBelowG() * (cohort.Root + cohort.Wood)) - cohort.Root));// gC
                    cohort.Root += (ushort)(RootAlloc / cohort.species.CFracBiomass()); // gDW

                    float WoodAlloc = rootpluswoodalloc - RootAlloc;// gC

                    cohort.Wood += (ushort)(WoodAlloc / cohort.species.CFracBiomass());// DW

                }
                //}

            }
        }