Exemplo n.º 1
0
    private void MakePlots()
    {
      if (!PlotsMade) //Only do this once
      {

        Model mShe = new Model(SheFileName);
        DFS3 dfs = new DFS3(Dfs3FileName);
        Item dfsI = dfs.Items[ItemNumber - 1];

        List<TimestampSeries> well_Concentration = new List<TimestampSeries>();

        int[] TimeSteps = ParseString(TimeStepsAsString, 0, dfs.NumberOfTimeSteps - 1);
        int[] WellNumbers = ParseString(WellsAsString, 0, mShe.ExtractionWells.Count - 1);

        List<MikeSheWell> wells = new List<MikeSheWell>();
        foreach (int j in WellNumbers)
          wells.Add(mShe.ExtractionWells[j]);

        foreach (int i in TimeSteps)
        {
          int k = 0;
          foreach (var w in wells)
          {
            if (i == TimeSteps[0])
              well_Concentration.Add(new TimestampSeries(w.ID, new Unit(dfsI.EumQuantity.UnitAbbreviation, 1, 0)));
            well_Concentration[k].Items.Add(new TimestampValue(dfs.TimeSteps[i], (dfs.GetData(i, ItemNumber)[w.Row, w.Column, w.Layer])));
            k++;
          }
        }

        //Sets the upper title
        Header.Content = dfsI.Name;

        //Sets the title of the y-axis
        var ytitle = new VerticalAxisTitle();
        ytitle.Content = dfsI.EumQuantity.ItemDescription + " [" + dfsI.EumQuantity.UnitAbbreviation + "]";
        TheChart.Children.Add(ytitle);

        int l = 0;
        //Loop the wells for plotting
        foreach (var w in wells)
        {
          if (g != null)
          {
            TheChart.Children.Remove(g);
            TheChart.FitToView();
          }

          var axis = new Microsoft.Research.DynamicDataDisplay.Charts.HorizontalDateTimeAxis();
          TheChart.MainHorizontalAxis = axis;
          TheChart.MainVerticalAxis = new Microsoft.Research.DynamicDataDisplay.Charts.VerticalAxis();
          //set the data source
          EnumerableDataSource<TimestampValue> ds = new EnumerableDataSource<TimestampValue>(well_Concentration[l].Items);
          ds.SetXMapping(var => axis.ConvertToDouble(var.Time));
          ds.SetYMapping(var => var.Value);
          //create the graph
          g = TheChart.AddLineGraph(ds, new Pen(Brushes.Black, 3), new PenDescription(w.ID));
         //create a filename
          outfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Dfs3FileName), "Well_No" + "_" + WellNumbers[l].ToString() + "_" + dfsI.EumQuantity.ItemDescription);
          //now save to file          
          this.UpdateLayout();

          MainWindow.SaveScreen(this, outfile + ".jpg", (int)ActualWidth, (int)ActualHeight);


          //Now create the dfs0-file
          using (DFS0 dfs0 = new DFS0(outfile + ".dfs0", 1))
          {
            dfs0.FirstItem.Name = dfsI.Name;
            dfs0.FirstItem.EumItem = dfsI.EumItem;
            dfs0.FirstItem.EumUnit = dfsI.EumUnit;
            dfs0.FirstItem.ValueType = dfsI.ValueType;

            int t = 0;
            foreach (var v in well_Concentration[l].Items)
            {
              dfs0.InsertTimeStep(v.Time);
              dfs0.SetData(t, 1, v.Value);
              t++;
            }
          }

          //Now create the text-file
          using (StreamWriter sw = new StreamWriter(outfile + ".txt", false))
          {
            foreach (var v in well_Concentration[l].Items)
            {
              sw.WriteLine(v.Time + "; " + v.Value);
            }
          }
          l++;
        }
        mShe.Dispose();
        dfs.Dispose();
        PlotsMade = true;
      }
    }
Exemplo n.º 2
0
        private void MakePlots()
        {
            if (!PlotsMade) //Only do this once
            {
                Model mShe = new Model(SheFileName);
                DFS3  dfs  = new DFS3(Dfs3FileName);
                Item  dfsI = dfs.Items[ItemNumber - 1];

                List <TimestampSeries> well_Concentration = new List <TimestampSeries>();

                int[] TimeSteps   = ParseString(TimeStepsAsString, 0, dfs.NumberOfTimeSteps - 1);
                int[] WellNumbers = ParseString(WellsAsString, 0, mShe.ExtractionWells.Count - 1);

                List <MikeSheWell> wells = new List <MikeSheWell>();
                foreach (int j in WellNumbers)
                {
                    wells.Add(mShe.ExtractionWells[j]);
                }

                foreach (int i in TimeSteps)
                {
                    int k = 0;
                    foreach (var w in wells)
                    {
                        if (i == TimeSteps[0])
                        {
                            well_Concentration.Add(new TimestampSeries(w.ID, new Unit(dfsI.EumQuantity.UnitAbbreviation, 1, 0)));
                        }
                        well_Concentration[k].Items.Add(new TimestampValue(dfs.TimeSteps[i], (dfs.GetData(i, ItemNumber)[w.Row, w.Column, w.Layer])));
                        k++;
                    }
                }

                //Sets the upper title
                Header.Content = dfsI.Name;

                //Sets the title of the y-axis
                var ytitle = new VerticalAxisTitle();
                ytitle.Content = dfsI.EumQuantity.ItemDescription + " [" + dfsI.EumQuantity.UnitAbbreviation + "]";
                TheChart.Children.Add(ytitle);

                int l = 0;
                //Loop the wells for plotting
                foreach (var w in wells)
                {
                    if (g != null)
                    {
                        TheChart.Children.Remove(g);
                        TheChart.FitToView();
                    }

                    var axis = new Microsoft.Research.DynamicDataDisplay.Charts.HorizontalDateTimeAxis();
                    TheChart.MainHorizontalAxis = axis;
                    TheChart.MainVerticalAxis   = new Microsoft.Research.DynamicDataDisplay.Charts.VerticalAxis();
                    //set the data source
                    EnumerableDataSource <TimestampValue> ds = new EnumerableDataSource <TimestampValue>(well_Concentration[l].Items);
                    ds.SetXMapping(var => axis.ConvertToDouble(var.Time));
                    ds.SetYMapping(var => var.Value);
                    //create the graph
                    g = TheChart.AddLineGraph(ds, new Pen(Brushes.Black, 3), new PenDescription(w.ID));
                    //create a filename
                    outfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Dfs3FileName), "Well_No" + "_" + WellNumbers[l].ToString() + "_" + dfsI.EumQuantity.ItemDescription);
                    //now save to file
                    this.UpdateLayout();

                    MainWindow.SaveScreen(this, outfile + ".jpg", (int)ActualWidth, (int)ActualHeight);


                    //Now create the dfs0-file
                    using (DFS0 dfs0 = new DFS0(outfile + ".dfs0", 1))
                    {
                        dfs0.FirstItem.Name      = dfsI.Name;
                        dfs0.FirstItem.EumItem   = dfsI.EumItem;
                        dfs0.FirstItem.EumUnit   = dfsI.EumUnit;
                        dfs0.FirstItem.ValueType = dfsI.ValueType;

                        int t = 0;
                        foreach (var v in well_Concentration[l].Items)
                        {
                            dfs0.InsertTimeStep(v.Time);
                            dfs0.SetData(t, 1, v.Value);
                            t++;
                        }
                    }

                    //Now create the text-file
                    using (StreamWriter sw = new StreamWriter(outfile + ".txt", false))
                    {
                        foreach (var v in well_Concentration[l].Items)
                        {
                            sw.WriteLine(v.Time + "; " + v.Value);
                        }
                    }
                    l++;
                }
                mShe.Dispose();
                dfs.Dispose();
                PlotsMade = true;
            }
        }