protected static speciesattrs species_Attrs = null;//Pointer to an attached set of species Attributes. //Constructor. This constructor can only be used on the first creation //instance of class species. It sets the number of different varieties of species in the model. public species(uint n) { if (numSpec != 0) { throw new Exception("SPECIES::SPECIES(int)-> Number of species may only be set once at construction."); } all_species = new specie[n]; for (int i = 0; i < n; i++) { all_species[i] = new specie(i); } numSpec = n; currentSpec = 0; }
//start killing trees gradually at the 80 % longevity until they reach their longevity // modified version of function : void SUCCESSION::kill(SPECIE *s, SPECIESATTR *sa) public static void KillTrees(uint local_r, uint local_c) { site local_site = gl_sites[local_r, local_c]; for (int k = 1; k <= specAtNum; ++k)//sites.specNum { int longev = gl_spe_Attrs[k].Longevity; int numYears = longev / 5; float chanceMod = 0.8f / (numYears + 0.00000001f); float chanceDeath = 0.2f; int m_beg = (longev - numYears) / gl_sites.SuccessionTimeStep; int m_end = longev / gl_sites.SuccessionTimeStep; 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 * gl_sites.SuccessionTimeStep / 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; } } }
//Constructor. Should be used on all instance constructions other than the //first. This may be used on the first instance of construction but should //be followed by a call to setNumber before the second construction instance. public species() { if (numSpec == 0) { all_species = null; currentSpec = 0; } else { all_species = new specie[numSpec]; currentSpec = 0; for (int i = 0; i < numSpec; i++) { all_species[i] = new specie(i); all_species[i].AGELISTAllocateVector(i); } } }
public void copy(specie[] in_all_species, uint in_numSpec) { if (in_all_species == null) { return; } numSpec = in_numSpec; all_species = new specie[numSpec]; for (int i = 0; i < numSpec; i++) { all_species[i] = new specie(i); all_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); }
//This will perform a reclassification based upon the oldest cohort upon a landis stand. //The cohorts will be scaled into 16 age classes. public static void ageReclass(map8 m) { m.dim(snr, 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 (uint i = snr; i >= 1; i--) { for (uint j = 1; j <= snc; j++) { if (PlugIn.gl_sites.locateLanduPt(i, j).active()) { m[i, j] = 0; uint myage = 0; site local_site = PlugIn.gl_sites[i, j]; specie s = local_site.first(); while (s != null) { uint temp = s.oldest(); if (temp > myage) { myage = temp; } s = local_site.next(); } m[i, j] = (ushort)(myage / time_step); } else if (PlugIn.gl_sites.locateLanduPt(i, j).lowland()) { m[i, j] = (ushort)(map8.MaxValueforLegend - 3); } else if (PlugIn.gl_sites.locateLanduPt(i, j).water()) { m[i, j] = (ushort)(map8.MaxValueforLegend - 2); } else { m[i, j] = (ushort)(map8.MaxValueforLegend - 1); } } } }
//This will faciliate age output at 10 year step for species specified in species age index file. //This will output age at 10 year step for each specified species. //The cohorts can be up to 50 age classes, 0-500 years. public static void speciesAgeMap(map8 m, string ageFile) { int curSp = PlugIn.gl_spe_Attrs.current(ageFile); m.dim(snr, 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 (uint i = snr; i >= 1; i--) { for (uint j = 1; j <= snc; j++) { if (PlugIn.gl_sites.locateLanduPt(i, j) == null) { throw new Exception("Invalid landunit error\n"); } if (PlugIn.gl_sites.locateLanduPt(i, j).active()) { m[i, j] = 0; //where species not presents if (PlugIn.gl_sites[i, j] == null) { throw new Exception("No site\n"); } specie s = PlugIn.gl_sites[i, j].current(curSp); if (s == null) { Console.WriteLine("{0}\n", curSp); throw new Exception("No Species\n"); } if (s.query()) { m[i, j] = (ushort)(s.oldest() / time_step); //compare ageReclass which uses +3 there??? if (m[i, j] > map8.MaxValueforLegend - 4) //maximum longevity is 640 years// Notice 66 means 640 years { m[i, j] = (ushort)(map8.MaxValueforLegend - 4); } } } else if (PlugIn.gl_sites.locateLanduPt(i, j).water()) { m[i, j] = (ushort)(map8.MaxValueforLegend - 2); } else if (PlugIn.gl_sites.locateLanduPt(i, j).lowland()) { m[i, j] = (ushort)(map8.MaxValueforLegend - 3); } else { m[i, j] = (ushort)(map8.MaxValueforLegend - 1); } } } }
//This will reclassify a singular site. M is the number of possible output classes. private int reclassifySite(site site_in, int m) { float[] sval = new float[MAX_RECLASS]; specie local_specie = site_in.first(); int j = 1; while (local_specie != null) { float c = (float)local_specie.oldest() / maximum[j - 1]; if (c > 1.0) { c = 1.0f; } for (int i = 1; i <= m; i++) { if (BOOL[i, j] != 0) { if (BOOL[i, j] > 0) { sval[i] += c; } else { sval[i] -= c; } if (sval[i] != 0) { if (sval[i] > 1.0) { sval[i] = 1.0f; } if (sval[i] < 0.0) { sval[i] = 0.0f; } } } } j++; local_specie = site_in.next(); } int mx = 0; float mxVal = 0.0f; for (int i = 1; i <= m; i++) { if (sval[i] > mxVal) { mxVal = sval[i]; mx = i; } } if (mxVal > 0.0) { return(mx); } else { return(m + 1); } }
//This will calculate the reclassification value given a specie list for a site. private int reclassificationValue(specie s) { return(s.number()); }
//This will reclassify sites from user defined class file and the existing age //maps. Class file is a file containing site descriptions for a set of class. //Age maps involved in the reclassification need to be created before. public static void reclassify(int timeStep, string[] ageMaps) { uint specAtNum = PlugIn.gl_spe_Attrs.NumAttrs; uint yDim = PlugIn.gl_sites.numRows; uint xDim = PlugIn.gl_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 = PlugIn.gl_spe_Attrs.current(speciesName); //read age map file from output directory str = PlugIn.gl_param.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 (uint k = yDim; k > 0; k--) { for (uint j = 1; j <= xDim; j++) { int coverType = inAgeMap.Read(); if (coverType == 255) //species absence { specie s = PlugIn.gl_sites[k, j].current(curSp); s.clear(); } else if (coverType >= 3) //0-empty 1-water 2-nonforest { specie s = PlugIn.gl_sites[k, j].current(curSp); s.clear(); s.set((coverType - 2) * PlugIn.gl_sites.SuccessionTimeStep); } } //end for } //end for } //end using } //end for }