public static void ageReclass(map8 m) { m.dim((uint)snr, (uint)snc); m.rename("Age class representation"); for (uint j = 1; j < map8.MapmaxValue; j++) { m.assignLeg(j, ""); } string str; //J.Yang hard coding changing itr*sites.TimeStep to itr //J.Yang maxLeg is defined as 256 in map8.h, therefore, maximum age cohorts it can output is 254 for (uint i = 1; i < map8.MaxValueforLegend - 4; i++) { str = string.Format("{0: } - {1: } yr", (i - 1) * time_step + 1, i * time_step); m.assignLeg(i, str); } m.assignLeg(0, "NoSpecies"); m.assignLeg(map8.MaxValueforLegend - 1, "N/A"); m.assignLeg(map8.MaxValueforLegend - 2, "Water"); m.assignLeg(map8.MaxValueforLegend - 3, "NonForest"); str = string.Format(" >{0: } yr", (map8.MaxValueforLegend - 4 - 1) * time_step); m.assignLeg(map8.MaxValueforLegend - 4, str); for (int i = snr; i >= 1; i--) { for (int j = 1; j <= snc; j++) { if (Program.sites.locateLanduPt(i, j).active()) { m[(uint)i, (uint)j] = 0; uint myage = 0; Site local_site = Program.sites[i, j]; Specie s = local_site.first(); while (s != null) { uint temp = (uint)s.oldest(); if (temp > myage) { myage = temp; } s = local_site.next(); } m[(uint)i, (uint)j] = (ushort)(myage / time_step); } else if (Program.sites.locateLanduPt(i, j).lowland()) { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 3); } else if (Program.sites.locateLanduPt(i, j).water()) { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 2); } else { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 1); } } } }
public Species(int n) { species = null; if (numSpec == 0) { species = new Specie[n]; for (int i = 0; i < n; i++) { species[i] = new Specie(); } numSpec = n; currentSpec = 0; } else { throw new Exception("SPECIES::SPECIES(int)-> Number of species may only be set once at construction"); } }
public static void reclassify(int timeStep, string[] ageMaps) { int specAtNum = Program.speciesAttrs.Number(); int yDim = Program.sites.numRows(); int xDim = Program.sites.numColumns(); for (int i = 0; i < specAtNum; i++) { string str = ageMaps[i] + ".age"; string speciesName; //read species name from ageIndex file using (StreamReader inAgeIndex = new StreamReader(str)) { speciesName = system1.read_string(inAgeIndex); } int curSp = Program.speciesAttrs.current(speciesName); //read age map file from output directory str = Program.parameters.outputDir + "/" + ageMaps[i] + timeStep.ToString() + ".gis"; using (BinaryReader inAgeMap = new BinaryReader(File.Open(str, FileMode.Open))) { byte[] dest = new byte[128]; inAgeMap.Read(dest, 0, 128); // read inAgeMap for (int k = yDim; k > 0; k--) { for (int j = 1; j <= xDim; j++) { int coverType = inAgeMap.Read(); if (coverType == 255) //species absence { Specie s = Program.sites[k, j].current(curSp); s.clear(); } else if (coverType >= 3) //0-empty 1-water 2-nonforest { Specie s = Program.sites[k, j].current(curSp); s.clear(); s.set((coverType - 2) * Program.sites.TimeStep); } } //end for } //end for } //end using } //end for }
public Species() { species = null; if (numSpec == 0) { species = null; currentSpec = 0; } else { species = new Specie[numSpec]; currentSpec = 0; for (int i = 0; i < numSpec; i++) { species[i] = new Specie(); species[i].AGELISTAllocateVector(i); } } }
public void copy(Specie[] in_all_species, int in_numSpec) { if (in_all_species == null) { return; } numSpec = in_numSpec; species = new Specie[numSpec]; for (int i = 0; i < numSpec; i++) { species[i] = new Specie(i); species[i].copy(in_all_species[i]); } currentSpec = 0; }
public void copy(Specie in_specie) { if (in_specie == null) { return; } vegPropagules = in_specie.vegPropagules; disPropagules = in_specie.disPropagules; AvailableSeed = in_specie.AvailableSeed; TreesFromVeg = in_specie.TreesFromVeg; MatureTree = in_specie.MatureTree; index = in_specie.index; base.copy(in_specie.agevector); }
public static void KillTrees(uint local_r, uint local_c) { Site local_site = sites[(int)local_r, (int)local_c]; for (int k = 1; k <= specAtNum; ++k)//sites.specNum { int longev = speciesAttrs[k].longevity; int numYears = longev / 5; float chanceMod = 0.8f / (numYears + 0.00000001f); float chanceDeath = 0.2f; int m_beg = (longev - numYears) / sites.TimeStep; int m_end = longev / sites.TimeStep; Specie local_specie = local_site.SpecieIndex(k); for (int m = m_beg; m <= m_end; m++) { int tmpTreeNum = (int)local_specie.getTreeNum(m, k); int tmpMortality = 0; if (tmpTreeNum > 0) { float local_threshold = chanceDeath * sites.TimeStep / 10; for (int x = 1; x <= tmpTreeNum; x++) { if (system1.frand() < local_threshold) { tmpMortality++; } } local_specie.setTreeNum(m, k, Math.Max(0, tmpTreeNum - tmpMortality)); } chanceDeath += chanceMod; } } }
public static void speciesAgeMap(map8 m, string ageFile) { int curSp = Program.speciesAttrs.current(ageFile); m.dim((uint)snr, (uint)snc); m.rename(ageFile); string str; for (uint i = 1; i < map8.maxLeg - 4; i++) { str = string.Format("{0: } - {1: } yr", (i - 1) * time_step + 1, i * time_step); m.assignLeg(i, str); } m.assignLeg(0, "NotPresent"); m.assignLeg(map8.MaxValueforLegend - 1, "N/A"); m.assignLeg(map8.MaxValueforLegend - 2, "Water"); m.assignLeg(map8.MaxValueforLegend - 3, "NonForest"); str = string.Format(" >{0} yr", (map8.maxLeg - 4 - 1) * time_step); m.assignLeg(map8.MaxValueforLegend - 4, str); for (int i = snr; i >= 1; i--) { for (int j = 1; j <= snc; j++) { if (Program.sites.locateLanduPt(i, j) == null) { throw new Exception("Invalid landunit error\n"); } if (Program.sites.locateLanduPt(i, j).active()) { m[(uint)i, (uint)j] = 0; //where species not presents if (Program.sites[i, j] == null) { throw new Exception("No site\n"); } Specie s = Program.sites[i, j].current(curSp); if (s == null) { Console.WriteLine("{0}\n", curSp); throw new Exception("No Species\n"); } if (s.query()) { m[(uint)i, (uint)j] = (ushort)(s.oldest() / time_step); //compare ageReclass which uses +3 there??? if (m[(uint)i, (uint)j] > map8.MaxValueforLegend - 4) //maximum longevity is 640 years// Notice 66 means 640 years { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 4); } } } else if (Program.sites.locateLanduPt(i, j).water()) { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 2); } else if (Program.sites.locateLanduPt(i, j).lowland()) { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 3); } else { m[(uint)i, (uint)j] = (ushort)(map8.MaxValueforLegend - 1); } } } }