internal void Copy(Land_type_Attributes gl_land_attrs) { numLU = (uint)Land_type_Attributes.Landtype_count; for (int i = 0; i < Land_type_Attributes.Landtype_count; ++i) { //land_Units[i] = new landunit(); land_Units[i].Name = PlugIn.ModelCore.Ecoregions[i].Name; string name = land_Units[i].Name; if (string.Equals(name, "empty", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "road", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.PASSIVE; } else if (string.Equals(name, "water", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.WATER; } else if (string.Equals(name, "wetland", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.WETLAND; } else if (string.Equals(name, "bog", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.BOG; } else if (string.Equals(name, "lowland", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.LOWLAND; } else if (string.Equals(name, "nonforest", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.NONFOREST; } else if (string.Equals(name, "grassland", StringComparison.OrdinalIgnoreCase)) { land_Units[i].Status = landunit.land_status.GRASSLAND; } else { land_Units[i].Status = landunit.land_status.ACTIVE; } land_Units[i].Index = i; land_Units[i].LtID = i; land_Units[i].MinShade = Land_type_Attributes.get_min_shade(i); land_Units[i].ProbReproductionOriginalBackup = new float[land_Units[i].Species_Attrs.NumAttrs]; } }
public override void LoadParameters(string dataFile, ICore mCore) { modelCore = mCore; //Console.WriteLine("Run: From {0} to {1}, current {2}", modelCore.StartTime, modelCore.EndTime, modelCore.CurrentTime); //Console.WriteLine("\n\nhere datefile = {0}\n\n", dataFile); InputParametersParser parser = new InputParametersParser(); gl_param = Landis.Data.Load <InputParameters>(dataFile, parser); //Init_Output.GDLLMode = gl_param.read(dataFile); //PlugIn.gl_spe_Attrs.read(saFile); PlugIn.gl_spe_Attrs.read(PlugIn.gl_param.ExtraSpecAtrFile); //PlugIn.gl_landUnits.attach(PlugIn.gl_spe_Attrs); //PlugIn.gl_landUnits.read(PlugIn.gl_param.LandUnitFile); //PlugIn.gl_sites.BiomassRead(PlugIn.gl_param.Biomassfile); BiomassParamParser bioparser = new BiomassParamParser(); Landis.Data.Load <BiomassParam>(PlugIn.gl_param.Biomassfile, bioparser); numSpecies = gl_spe_Attrs.NumAttrs; species.attach(PlugIn.gl_spe_Attrs); gl_landUnits.attach(PlugIn.gl_spe_Attrs); Land_type_AttributesParser parser2 = new Land_type_AttributesParser(); gl_land_attrs = Landis.Data.Load <Land_type_Attributes>(gl_param.LandUnitFile, parser2); gl_landUnits.Copy(gl_land_attrs); Establishment_probability_AttributesParser parser3 = new Establishment_probability_AttributesParser(); //var establish = Landis.Data.Load <Establishment_probability_Attributes>(gl_param.VarianceSECFile, parser3); }
/* * 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()