Example #1
0
        public void build_hss_file(string path, hssFile hss, List <cellData> files)
        {
            string output = String.Format("{0} {1} {2} {3}{4}", hss.MaxHSSSource, hss.MaxHSSCells, hss.MaxHSSStep, hss.RunOption, Environment.NewLine);

            output += string.Format("{0} {1} {2}{3}", hss.faclength, hss.factime, hss.facmass, Environment.NewLine);
            output += string.Format("{0}{1}", hss.nHSSSource, Environment.NewLine);
            foreach (cellData file in files)
            {
                output += string.Format("{0} {1}{2}", file.HSSFileName, file.inHSSFile, Environment.NewLine);
                output += string.Format("{0} {1} {2} {3} {4}{5}", file.kSource, file.iSource, file.jSource, file.SourceName, file.iHSSComp, Environment.NewLine);
            }
            write_output(path + "mt3d.hss", output);
        }
Example #2
0
        public void buildHSS(char delim, int start, int end, string path)
        {
            List <cellData> files = new List <cellData>();
            Dictionary <string, List <datafile> > data = new Dictionary <string, List <datafile> >();
            hssFile hss = new hssFile();

            log = new List <string>();
            string log_str = "";

            foreach (hss_data_files file in source)
            {
                if (file.i != null && file.i != "" && file.j != null && file.j != "")
                {
                    string   datFileName = String.Format("i{0}j{1}_HSS.dat", file.i, file.j);
                    cellData cell        = files.Where(f => f.HSSFileName == file.source).FirstOrDefault();
                    if (cell == null || cell.HSSFileName == null)
                    {
                        log.Add(string.Format("{0}:  processing file '{1}'; column {2}; cell {3}-{4}; time frame {5} - {6} ",
                                              DateTime.Now, file.source, file.col, file.i, file.j, start, end));
                        cell             = new cellData();
                        cell.HSSFileName = datFileName;
                        cell.iHSSComp    = "COPC";
                        cell.inHSSFile   = "";//file.id.ToString();
                        cell.iSource     = file.i.ToString();
                        cell.jSource     = file.j.ToString();
                        if (water_lvl.Keys.Contains(int.Parse(file.i)) && water_lvl[int.Parse(file.i)].Keys.Contains(int.Parse(file.j)))
                        {
                            cell.kSource = water_lvl[int.Parse(file.i)][int.Parse(file.j)].ToString();
                        }
                        else
                        {
                            cell.kSource = file.k.ToString();
                        }
                        cell.SourceName = file.id.ToString();
                        files.Add(cell);
                    }
                    int col_year = source.Where(s => s.source == file.source && s.time == true).Select(s => s.col).First();
                    IEnumerable <string> lines = File.ReadLines(file.source);
                    double prev_year           = start;
                    double days       = 0;
                    bool   start_year = true;

                    foreach (string line in lines)
                    {
                        string[] temp = line.Split(new[] { delim }, StringSplitOptions.None);
                        double   year = 0;

                        if (!data.ContainsKey(datFileName))
                        {
                            data.Add(datFileName, new List <datafile>());
                        }

                        if (double.TryParse(temp[col_year], out year))
                        {
                            if (year >= start && year <= end)
                            {
                                double x = 0;

                                if (double.TryParse(temp[file.col], out x))
                                {
                                    if (x > 0)
                                    {
                                        x = x / 365.25;
                                    }
                                    //if the first record is > than the start date, then backfill previous years.
                                    if (start_year)
                                    {
                                        if (year > start)
                                        {
                                            log.Add(string.Format("{0}:  Backfilling missing years ({1} - {2}",
                                                                  DateTime.Now, start, year - 1));
                                            for (int i = start; i < year; i++)
                                            {
                                                if (i > start)
                                                {
                                                    log_str = string.Format("{0}:  year calc: (({1} - {2}) * 365.25) + {3} = ",
                                                                            DateTime.Now, i, i - 1, days);
                                                    days += year_to_days(i - 1, i);
                                                    log.Add(log_str + days.ToString());
                                                }

                                                datafile rec = data[datFileName].FirstOrDefault(d => d.year == days);
                                                data[datFileName].Add(datafile_rec(days, 0, data[datFileName].FirstOrDefault(d => d.year == days)));
                                                if (days > 0)
                                                {
                                                    data[datFileName].Add(datafile_rec(days, 0, data[datFileName].FirstOrDefault(d => d.year == days)));
                                                }
                                                prev_year = i;
                                            }
                                            log.Add(string.Format("{0}:  End of backfilled years",
                                                                  DateTime.Now, start, year - 1));
                                        }
                                        start_year = false;
                                    }
                                    if (year > start)
                                    {
                                        log_str = string.Format("{0}:  year calc: (({1} - {2}) * 365.25) + {3} = ",
                                                                DateTime.Now, year, prev_year, days);
                                        days += year_to_days(prev_year, year);
                                        log.Add(log_str + days.ToString());
                                    }
                                    data[datFileName].Add(datafile_rec(days, x, data[datFileName].FirstOrDefault(d => d.year == days)));
                                    if (days > 0)
                                    {
                                        data[datFileName].Add(datafile_rec(days, x, data[datFileName].FirstOrDefault(d => d.year == days)));
                                    }
                                    prev_year = year;
                                }
                            }
                        }
                    }
                }
            }
            hss.MaxHSSSource = files.Count;
            hss.MaxHSSCells  = files.Count;
            hss.nHSSSource   = files.Count;
            hss.MaxHSSStep   = (end - start) + 2;
            string  units  = "";
            outputs output = new outputs(units);

            output.build_hss_file(path, hss, files);
            output.build_hss_dat_files(path, data);
            output.build_log_file(path, log);
            log = new List <string>();
        }