public void ReprodBackup() { for (int i = 0; i < numLU; i++) { landunit local_landunit = land_Units[i]; for (int j = 0; j < numSpecies; j++) { local_landunit.set_probReproductionOriginalBackup(j, local_landunit.get_probReproduction(j)); } } }
//Constructor, sets upper limit for number of land units. public landunits(int n = defines.MAX_LANDUNITS) { numLU = 0; currentLU = 0; maxLU = n; land_Units = new landunit[n]; for (int i = 0; i < n; i++) { land_Units[i] = new landunit(); } }
public void ReprodUpdate(int year) { if (flagforSECFile == 3 || flagforSECFile == 0) { return; } float local_val = (1 + VectorIteration[year - 1]) * timestep / 10.0f; for (int i = 0; i < numLU; i++) { //for (int j = 0; j < numSpecies; j++) // land_Units[i].probReproduction[j] = land_Units[i].probReproductionOriginalBackup[j] / 10 * timestep * local_val; landunit local_landunit = land_Units[i]; for (int j = 0; j < numSpecies; j++) { local_landunit.set_probReproduction(j, local_landunit.get_probReproductionOriginalBackup(j) * local_val); } } }
/* * public static void updateLandtypeMap8(BinaryReader ltMapFile) * { * uint[] dest = new uint[32]; * * //LDfread((char*)dest, 4, 32, ltMapFile); * for (int i = 0; i < 32; i++) * dest[i] = ltMapFile.ReadUInt32(); * * * int b16or8; * if ((dest[1] & 0xff0000) == 0x020000) * b16or8 = 16; * else if ((dest[1] & 0xff0000) == 0) * b16or8 = 8; * else * { * b16or8 = -1; * throw new Exception("Error: IO: Landtype map is neither 16 bit or 8 bit."); * } * * uint nCols = dest[4]; * uint nRows = dest[5]; * * * uint xDim = gl_sites.numColumns; * uint yDim = gl_sites.numRows; * * if ((nCols != xDim) || (nRows != yDim)) * throw new Exception("landtype map and species map do not match."); * * * * if (b16or8 == 8) //8 bit * { * for (uint i = yDim; i > 0; i--) * { * for (uint j = 1; j <= xDim; j++) * { * int coverType = ltMapFile.Read(); * * if (coverType >= 0) * gl_sites.fillinLanduPt(i, j, gl_landUnits[coverType]); * else * throw new Exception("illegel landtype class found."); * } * } * } * else if (b16or8 == 16) //16 bit * { * for (uint i = yDim; i > 0; i--) * { * for (uint j = 1; j <= xDim; j++) * { * int coverType = ltMapFile.ReadUInt16(); * * if (coverType >= 0) * gl_sites.fillinLanduPt(i, j, gl_landUnits[coverType]); * else * throw new Exception("illegel landtype class found."); * } * } * } * * } */ //Main program. This contains start and shut down procedures as well as the main iteration loop. public override void Run() { int i = modelCore.TimeSinceStart; int i_d_timestep = i / gl_sites.SuccessionTimeStep; for (int r = 0; r < gl_landUnits.Num_Landunits; ++r) { gl_landUnits[r].MinShade = Land_type_Attributes.get_min_shade(r); float[] rd = new float[4]; rd[0] = Land_type_Attributes.get_gso(0, r); rd[1] = Land_type_Attributes.get_gso(1, r); rd[2] = Land_type_Attributes.get_gso(2, r); rd[3] = gl_land_attrs.get_maxgso(i, r); gl_landUnits[r].MaxRDArrayItem = rd; gl_landUnits[r].MaxRD = rd[3]; } //Simulation loops//////////////////////////////////////////////// //for (int i = 1; i <= numbOfIter * gl_sites.TimeStep; i++) //{ if (i % gl_sites.SuccessionTimeStep == 0) { if (gl_param.FlagforSECFile == 3) { int index = i_d_timestep - 1; if (index == 0) { SEC_landtypefiles.Clear(); SEC_gisfiles.Clear(); /* * using (StreamReader FpSECfile = new StreamReader(gl_param.VarianceSECFile)) * { * int num_of_files = system1.read_int(FpSECfile); * * for (int ii_count_num = 0; ii_count_num < num_of_files; ii_count_num++) * { * string SECfileMapGIS = system1.read_string(FpSECfile); * string SECfileNametemp = system1.read_string(FpSECfile); * * SEC_landtypefiles.Add(SECfileNametemp); * SEC_gisfiles.Add(SECfileMapGIS); * } * } */ if (index < gl_land_attrs.year_arr.Count) { /*string SECfileNametemp = SEC_landtypefiles[index]; * * string SECfileMapGIS = SEC_gisfiles[index]; * * gl_param.LandUnitFile = SECfileNametemp; * * gl_landUnits.read(gl_param.LandUnitFile); */ Console.Write("\nEnvironment parameter Updated.\n"); string SECfileMapGIS = gl_land_attrs.Get_new_landtype_map(index); //strcpy(parameters.landUnitMapFile, SECfileMapGIS); gl_param.LandImgMapFile = SECfileMapGIS; /*Dataset simgFile = null; * * if ((simgFile = (Dataset)Gdal.Open(gl_param.LandImgMapFile, Access.GA_ReadOnly)) == null) //* landtype.img * { * Console.Write("Land Map Img file %s not found.\n", gl_param.LandImgMapFile); * * throw new Exception(gl_param.LandImgMapFile); * } * else * { * double[] adfGeoTransform = new double[6]; * * simgFile.GetGeoTransform(adfGeoTransform); * { * for (int ii = 0; ii < 6; ii++) * { * wAdfGeoTransform[ii] = adfGeoTransform[ii]; * } * } * * updateLandtypeImg8(simgFile); * * simgFile = null; * } */ Console.WriteLine("\nEnvironment map Updated."); landunit SECLog_use = gl_landUnits.first(); int ii_count = 0; using (StreamWriter fpLogFileSEC = new StreamWriter(fpLogFileSEC_name)) { fpLogFileSEC.Write("Year: {0}\n", i); for (; ii_count < gl_landUnits.Num_Landunits; ii_count++) { fpLogFileSEC.Write("Landtype{0}:\n", ii_count); for (int jj_count = 1; jj_count <= specAtNum; jj_count++) { fpLogFileSEC.Write("spec{0}: {1:N6}, ", jj_count, SECLog_use.probRepro(jj_count)); } SECLog_use = gl_landUnits.next(); fpLogFileSEC.Write("\n"); } } } } if (index > 0) { if (index < SEC_landtypefiles.Count) { /*gl_param.LandUnitFile = SEC_landtypefiles[index]; * //gl_param.landUnitMapFile = SEC_gisfiles[index]; * gl_param.LandImgMapFile = SEC_gisfiles[index]; * * gl_landUnits.read(gl_param.LandUnitFile); */ gl_param.LandImgMapFile = gl_land_attrs.Get_new_landtype_map(index); Console.WriteLine("\nEnvironment parameter Updated."); /*using(BinaryReader GISmap = new BinaryReader(File.Open(gl_param.landUnitMapFile, FileMode.Open))) * { * updateLandtypeMap8(GISmap); * }*/ /*Dataset ltimgFile = null; * * if ((ltimgFile = (Dataset)Gdal.Open(gl_param.LandImgMapFile, Access.GA_ReadOnly)) == null) //* landtype.img * { * Console.WriteLine("Land Map Img file {0} not found.", gl_param.LandImgMapFile); * * throw new Exception(gl_param.LandImgMapFile); * } * else * { * double[] adfGeoTransform = new double[6]; * * ltimgFile.GetGeoTransform(adfGeoTransform); * { * for (int ii = 0; ii < 6; ii++) * { * wAdfGeoTransform[ii] = adfGeoTransform[ii]; * } * } * * updateLandtypeImg8(ltimgFile); * * ltimgFile = null; * * }*/ Console.WriteLine("\nEnvironment map Updated."); landunit SECLog_use = gl_landUnits.first(); using (StreamWriter fpLogFileSEC = new StreamWriter(fpLogFileSEC_name)) { fpLogFileSEC.Write("Year: {0}\n", i); int ii_count = 0; for (; ii_count < gl_landUnits.Num_Landunits; ii_count++) { fpLogFileSEC.Write("Landtype{0}:\n", ii_count); for (int jj_count = 1; jj_count <= specAtNum; jj_count++) { fpLogFileSEC.Write("spec{0}: {1:N6}, ", jj_count, SECLog_use.probRepro(jj_count)); } SECLog_use = gl_landUnits.next(); fpLogFileSEC.Write("\n"); } } } } } }//end if Console.WriteLine("Processing succession at Year {0}", i); singularLandisIteration(i, pPDP); if (i % gl_sites.SuccessionTimeStep == 0 || i == numbOfIter * gl_sites.SuccessionTimeStep) { int[] frequency = new int[6] { 1, 1, 1, 1, 1, 1 }; if (i % (gl_sites.SuccessionTimeStep * freq[0]) == 0 && i_d_timestep <= numbOfIter) { In_Output.putOutput_Landis70Pro(0, i_d_timestep, freq); } if (i == gl_sites.SuccessionTimeStep * numbOfIter) { In_Output.putOutput_Landis70Pro(0, numbOfIter, frequency); } if (i % (gl_sites.SuccessionTimeStep * freq[4]) == 0 && i_d_timestep <= numbOfIter) { In_Output.putOutput(0, i_d_timestep, freq); } if (i == gl_sites.SuccessionTimeStep * numbOfIter) { In_Output.putOutput(0, numbOfIter, frequency); } In_Output.putOutput_AgeDistStat(i_d_timestep); } //} //Simulation loops end///////////////////////////////////////////////// }//end Run()
public static void succession_Landis70(pdp ppdp, int itr) { gl_sites.GetMatureTree(); //increase ages for (uint i = 1; i <= snr; ++i) { for (uint j = 1; j <= snc; ++j) { ppdp.addedto_sTSLMortality(i, j, (short)gl_sites.SuccessionTimeStep); //define land unit landunit l = gl_sites.locateLanduPt(i, j); if (l != null && l.active()) { site local_site = gl_sites[i, j]; for (int k = 1; k <= specAtNum; ++k) { local_site.SpecieIndex(k).GrowTree(); } } } //Console.ReadLine(); } //seed dispersal initiateRDofSite_Landis70(); Console.WriteLine("Seed Dispersal:"); for (uint i = 1; i <= snr; ++i) { //Console.WriteLine("\n{0}%\n", 100 * i / snr); for (uint j = 1; j <= snc; ++j) { //Console.WriteLine("i = {0}, j = {1}", i, j); landunit l = gl_sites.locateLanduPt(i, j); KillTrees(i, j); if (itr == 90 && i == 193 && j == 156) { Console.WriteLine("watch: {0}:{1}", "kill trees", gl_sites[193, 156].SpecieIndex(2).getAgeVector(1)); } if (l != null && l.active()) { float local_RD = gl_sites[i, j].RD; if (local_RD < l.MaxRDArray(0)) { gl_sites.SiteDynamics(0, i, j); } else if (local_RD >= l.MaxRDArray(0) && local_RD < l.MaxRDArray(1)) { gl_sites.SiteDynamics(1, i, j); } else if (local_RD >= l.MaxRDArray(1) && local_RD <= l.MaxRDArray(2)) { gl_sites.SiteDynamics(2, i, j); } else if (local_RD > l.MaxRDArray(2) && local_RD <= l.MaxRDArray(3)) { gl_sites.SiteDynamics(3, i, j); } else { Debug.Assert(local_RD > l.MaxRDArray(3)); gl_sites.SiteDynamics(4, i, j); } } } } Console.WriteLine("end succession_Landis70 once"); }