Beispiel #1
0
 public void loadSubBasins()
 {
     try
     {
         var filenames = System.IO.Directory.GetFiles(CurrentProject.SwattLocation);
         List <SwattProject.SubBasin> basins = new List <SwattProject.SubBasin>();
         foreach (var filename in filenames)
         {
             if (!filename.Contains("output"))
             {
                 int extensionStartIdx = filename.IndexOf(".sub");
                 int lastSlashIdx      = filename.LastIndexOf(@"\");
                 if (extensionStartIdx >= 0)
                 {
                     var basinName = filename.Substring(lastSlashIdx + 1, 9);
                     var basin     = new SwattProject.SubBasin {
                         name = basinName
                     };
                     this.loadHRUs(basin);
                     basins.Add(basin);
                 }
             }
         }
         this.CurrentProject.SubBasins = basins;
     } catch (Exception ex) { throw new ProjectException("Failed to load sub basins. " + ex.Message); }
 }
Beispiel #2
0
        public void loadHRUs(SwattProject.SubBasin basin)
        {
            var b = basin.name.Substring(0, 5);
            List <SwattProject.HRU> hrus = new List <SwattProject.HRU>();
            var filenames = System.IO.Directory.GetFiles(CurrentProject.SwattLocation, b + "*.hru");

            foreach (var fileName in filenames)
            {
                System.IO.StreamReader file = new System.IO.StreamReader(fileName);
                SwattProject.HRU       hru  = new SwattProject.HRU();
                CropCodes.Code         code;
                // Extract crop code from first line in file
                var line = file.ReadLine();
                line = line.Split()[5];
                line = line.Split(':')[1];
                Enum.TryParse(line, out code);
                // insert code
                hru.Code = code;
                // fill description
                hru.Description = CropCodes.getDescription(hru.Code);
                hru.SubBasin    = basin.Name;
                // add hru to sub basin
                hrus.Add(hru);
                file.Close();
            }
            basin.Hrus = hrus;
        }