示例#1
0
        private static void CreateCulvertDefaultFile(string culvertFileName, string culvertType)
        {
            var        data        = new Universal.CulvertValuesGroup();
            TextWriter culvertFile = new StreamWriter(culvertFileName);

            switch (Convert.ToInt32(culvertType))
            {
            case 0: //rating table
                data.Type     = 0;
                data.FileName = culvertFileName;
                data.NPoints  = 1;
                var myRt = new Universal.SecondaryTable[data.NPoints];
                myRt[0].Col0 = "0";
                myRt[0].Col1 = "0";
                data.Table   = myRt;
                data.Z1      = "0.0";
                data.Z1      = "0.0";
                data.UseElementElevations = 1;
                Universal.CulvertValuesGroups.Add(culvertFileName, data);

                // Write default data.
                culvertFile.WriteLine(data.NPoints);
                culvertFile.WriteLine(data.Table[0].Col0 + "   " + data.Table[0].Col1);
                culvertFile.WriteLine(data.Z1);
                culvertFile.WriteLine(data.Z2);
                culvertFile.WriteLine(data.UseElementElevations);
                break;

            case 1: // Variables type 1 (box)
                data.Type     = 1;
                data.Nb       = "1";
                data.FileName = culvertFileName;
                data.Ke       = "0.5";
                data.nc       = "0.025";
                data.Kp       = "1.5";
                data.M        = "0.5";
                data.cp       = "1.0";
                data.Y        = "0.8";
                data.m        = "0.7";
                data.Hb       = "1.0";
                data.Base     = "1.0";
                data.Z1       = "0.0";
                data.Z1       = "0.0";
                data.ComboManningSelectionIndex      = 0;
                data.ComboEntranceLossSelectionIndex = 0;
                data.ComboInletCoeffsSelectionIndex  = 0;
                data.UseElementElevations            = 1;
                Universal.CulvertValuesGroups.Add(culvertFileName, data);

                // Write default data.
                culvertFile.WriteLine(data.Nb);
                culvertFile.WriteLine(data.Ke);
                culvertFile.WriteLine(data.nc);
                culvertFile.WriteLine(data.Kp);
                culvertFile.WriteLine(data.M);
                culvertFile.WriteLine(data.cp);
                culvertFile.WriteLine(data.Y);
                culvertFile.WriteLine(data.m);
                culvertFile.WriteLine(data.Hb);
                culvertFile.WriteLine(data.Base);
                culvertFile.WriteLine(data.Z1);
                culvertFile.WriteLine(data.Z2);
                culvertFile.WriteLine(data.ComboManningSelectionIndex);
                culvertFile.WriteLine(data.ComboEntranceLossSelectionIndex);
                culvertFile.WriteLine(data.ComboInletCoeffsSelectionIndex);
                culvertFile.WriteLine(data.UseElementElevations);

                data.UseElementElevations = 1;

                break;

            case 2: // Variables type 2 (circular)
                data.Type     = 2;
                data.Nb       = "1";
                data.FileName = culvertFileName;
                data.Ke       = "0.5";
                data.nc       = "0.025";
                data.Kp       = "1.5";
                data.M        = "0.5";
                data.cp       = "1.0";
                data.Y        = "0.8";
                data.m        = "0.7";
                data.Dc       = "1";
                data.Z1       = "0.0";
                data.Z1       = "0.0";
                data.ComboManningSelectionIndex      = 0;
                data.ComboEntranceLossSelectionIndex = 0;
                data.ComboInletCoeffsSelectionIndex  = 0;
                data.UseElementElevations            = 1;
                Universal.CulvertValuesGroups.Add(culvertFileName, data);

                // Write default data.
                culvertFile.WriteLine(data.Nb);
                culvertFile.WriteLine(data.Ke);
                culvertFile.WriteLine(data.nc);
                culvertFile.WriteLine(data.Kp);
                culvertFile.WriteLine(data.M);
                culvertFile.WriteLine(data.cp);
                culvertFile.WriteLine(data.Y);
                culvertFile.WriteLine(data.m);
                culvertFile.WriteLine(data.Dc);
                culvertFile.WriteLine(data.Z1);
                culvertFile.WriteLine(data.Z2);
                culvertFile.WriteLine(data.ComboManningSelectionIndex);
                culvertFile.WriteLine(data.ComboEntranceLossSelectionIndex);
                culvertFile.WriteLine(data.ComboInletCoeffsSelectionIndex);
                culvertFile.WriteLine(data.UseElementElevations);
                break;
            }
            culvertFile.Close();
        }
示例#2
0
        private static void LoadCulvertsSecondaryData(string wholeFileName, ref string culvertType, ref List <string> warnings)
        {
            if (!Universal.CulvertValuesGroups.ContainsKey(wholeFileName))
            {
                if (File.Exists(wholeFileName))
                {
                    try
                    {
                        var          data = new Universal.CulvertValuesGroup();
                        StreamReader culvertFile;
                        culvertFile = File.OpenText(wholeFileName);
                        switch (Convert.ToInt32(culvertType)) //culvert type
                        {
                        case 0:                               //rating table
                            data.Type     = 0;
                            data.FileName = wholeFileName;
                            data.NPoints  = Convert.ToInt64(culvertFile.ReadLine());
                            var myRt = new Universal.SecondaryTable[data.NPoints];

                            for (int j = 0; j <= data.NPoints - 1; ++j)
                            {
                                string   next  = culvertFile.ReadLine();
                                string[] split = next.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                if (split.Length == 2)
                                {
                                    myRt[j].Col0 = split[0];
                                    myRt[j].Col1 = split[1];
                                }
                                else if (split.Length == 1)
                                {
                                    myRt[j].Col0 = split[0];
                                    myRt[j].Col1 = "";
                                }
                                else
                                {
                                    myRt[j].Col0 = "";
                                    myRt[j].Col1 = "";
                                }

                                //Universal.CulvertValuesGroups.V
                            }
                            data.Z1 = culvertFile.ReadLine();
                            data.Z2 = culvertFile.ReadLine();
                            data.UseElementElevations = Convert.ToInt32(culvertFile.ReadLine());

                            culvertFile.Close();
                            data.Table = myRt;
                            Universal.CulvertValuesGroups.Add(wholeFileName, data);
                            break;

                        case 1: // Variables type 1 (box)
                            data.Type     = 1;
                            data.Nb       = culvertFile.ReadLine();
                            data.FileName = wholeFileName;
                            data.Ke       = culvertFile.ReadLine();
                            data.nc       = culvertFile.ReadLine();
                            data.Kp       = culvertFile.ReadLine();
                            data.M        = culvertFile.ReadLine();
                            data.cp       = culvertFile.ReadLine();
                            data.Y        = culvertFile.ReadLine();
                            data.m        = culvertFile.ReadLine();
                            data.Hb       = culvertFile.ReadLine();
                            data.Base     = culvertFile.ReadLine();
                            data.Z1       = culvertFile.ReadLine();
                            data.Z2       = culvertFile.ReadLine();
                            data.ComboManningSelectionIndex      = Convert.ToInt32(culvertFile.ReadLine());
                            data.ComboEntranceLossSelectionIndex = Convert.ToInt32(culvertFile.ReadLine());
                            data.ComboInletCoeffsSelectionIndex  = Convert.ToInt32(culvertFile.ReadLine());
                            data.UseElementElevations            = Convert.ToInt32(culvertFile.ReadLine());

                            culvertFile.Close();
                            Universal.CulvertValuesGroups.Add(wholeFileName, data);
                            break;

                        case 2: // Variables type 2 (circular)
                            data.Type     = 2;
                            data.Nb       = culvertFile.ReadLine();
                            data.FileName = wholeFileName;
                            data.Ke       = culvertFile.ReadLine();
                            data.nc       = culvertFile.ReadLine();
                            data.Kp       = culvertFile.ReadLine();
                            data.M        = culvertFile.ReadLine();
                            data.cp       = culvertFile.ReadLine();
                            data.Y        = culvertFile.ReadLine();
                            data.m        = culvertFile.ReadLine();
                            data.Dc       = culvertFile.ReadLine();
                            data.Z1       = culvertFile.ReadLine();
                            data.Z2       = culvertFile.ReadLine();
                            data.ComboManningSelectionIndex      = Convert.ToInt32(culvertFile.ReadLine());
                            data.ComboEntranceLossSelectionIndex = Convert.ToInt32(culvertFile.ReadLine());
                            data.ComboInletCoeffsSelectionIndex  = Convert.ToInt32(culvertFile.ReadLine());
                            data.UseElementElevations            = Convert.ToInt32(culvertFile.ReadLine());

                            culvertFile.Close();
                            Universal.CulvertValuesGroups.Add(wholeFileName, data);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(Universal.Idioma("ERROR 1303130759: error reading file ", "ERROR 1303130759: error leyendo archivo ") +
                                        wholeFileName + ". " + ex.Message, "RiverFlow2D", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
                else
                {
                    // Culvert file doesn't exist. See if a default file was created.
                    if (warnings.IndexOf(wholeFileName) == -1)
                    {
                        // Write this default file.
                        warnings.Add(wholeFileName);

                        if (!(culvertType == "0" | culvertType == "1" | culvertType == "2"))
                        {
                            culvertType = "1";
                        }

                        CreateCulvertDefaultFile(wholeFileName, culvertType);
                    }
                }
            }
        }