コード例 #1
0
ファイル: FileWriters.cs プロジェクト: msruzy/hydronumerics
        /// <summary>
        /// Writes dfs0 files with head observations for the SelectedIntakes
        /// Only includes data within the period bounded by Start and End
        /// </summary>
        /// <param name="OutputPath"></param>
        public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
        {
            //Create the TSObject
            TSObject _tso  = new TSObjectClass();
            TSItem   _item = new TSItemClass();

            _item.DataType  = ItemDataType.Type_Float;
            _item.ValueType = ItemValueType.Instantaneous;
            _item.EumType   = 171;
            _item.EumUnit   = 1;
            _item.Name      = Intake.ToString();
            _tso.Add(_item);

            DateTime _previousTimeStep = DateTime.MinValue;

            //Select the observations
            var SelectedObs = Intake.HeadObservations.ItemsInPeriod(Start, End);
            int i           = 0;

            foreach (var Obs in SelectedObs)
            {
                //Only add the first measurement of the day
                if (Obs.Time != _previousTimeStep)
                {
                    _tso.Time.AddTimeSteps(1);
                    _tso.Time.SetTimeForTimeStepNr(i + 1, Obs.Time);
                    _item.SetDataForTimeStepNr(i + 1, (float)Obs.Value);
                }
                i++;
            }

            //Now write the DFS0.
            if (_tso.Time.NrTimeSteps != 0)
            {
                _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
                _tso.Connection.Save();
            }
        }
コード例 #2
0
      /// <summary>
      /// Writes a dfs0 with extraction data for each active intake in every plant. 
      /// Also writes the textfile that can be imported by the well editor.
      /// </summary>
      /// <param name="OutputPath"></param>
      /// <param name="Plants"></param>
      /// <param name="Start"></param>
      /// <param name="End"></param>
      public static void WriteExtractionDFS0(string OutputPath, IEnumerable<Plant> Plants, DateTime Start, DateTime End)
      {

        //Create the text file to the well editor.
        StreamWriter Sw = new StreamWriter(Path.Combine(OutputPath, "WellEditorImport.txt"), false, Encoding.Default);
        StreamWriter Sw2 = new StreamWriter(Path.Combine(OutputPath, "WellsWithMissingInfo.txt"), false, Encoding.Default);

        //Create the TSObject
        TSObject _tso = new TSObjectClass();
        string dfs0FileName = Path.Combine(OutputPath, "Extraction.dfs0");
        _tso.Connection.FilePath = dfs0FileName;
        TSItem _item;

        int eumtype = 330;
        int eumunit = 3;


        TSObject _tsoStat = new TSObjectClass();
        _tsoStat.Connection.FilePath = Path.Combine(OutputPath, "ExtractionStat.dfs0");
        Dictionary<int, double> Sum = new Dictionary<int, double>();
        Dictionary<int, double> SumSurfaceWater = new Dictionary<int, double>();
        Dictionary<int, double> SumNotUsed = new Dictionary<int, double>();

        int Pcount = 0;

        int NumberOfYears = End.Year - Start.Year + 1;

        //Dummy year because of mean step accumulated
        _tso.Time.AddTimeSteps(1);
        _tso.Time.SetTimeForTimeStepNr(1, new DateTime(Start.Year, 1, 1, 0, 0, 0));

        for (int i = 0; i < NumberOfYears; i++)
        {
          _tso.Time.AddTimeSteps(1);
          _tso.Time.SetTimeForTimeStepNr(i + 2, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));

          _tsoStat.Time.AddTimeSteps(1);
          _tsoStat.Time.SetTimeForTimeStepNr(i + 1, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));
          Sum.Add(i, 0);
          SumSurfaceWater.Add(i, 0);
          SumNotUsed.Add(i, 0);
        }

        int itemCount = 1;

        double[] fractions = new double[NumberOfYears];

          //loop the plants
        foreach (Plant P in Plants)
        {
          double val;
          //Create statistics on surface water for all plants
          for (int i = 0; i < NumberOfYears; i++)
          {
            if (P.SurfaceWaterExtrations.TryGetValue(Start.AddYears(i), out val))
              SumSurfaceWater[i] += val;
          }

          //Create statistics for plants without intakes
          if (P.PumpingIntakes.Count == 0)
          {
            //Create statistics on water not assigned
            for (int i = 0; i < NumberOfYears; i++)
            {
              if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                SumNotUsed[i] += val;
            }
          }
          else
          {
            //Create statistics
            for (int i = 0; i < NumberOfYears; i++)
            {
              if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                Sum[i] += val;
            }
            Pcount++;


            //Calculate the fractions based on how many intakes are active for a particular year.
            for (int i = 0; i < NumberOfYears; i++)
            {
              fractions[i] = 1.0 / P.PumpingIntakes.Count(var => var.Intake.well.UsedForExtraction & var.Start.Year <= Start.Year + i & var.End.Year >= Start.Year + i);
            }


            //Now loop the intakes
            foreach (PumpingIntake PI in P.PumpingIntakes)
            {
              IIntake I = PI.Intake;
              //Is it an extraction well?
              if (I.well.UsedForExtraction)
              {
                //If there is no screen information we cannot use it. 
                if (I.Screens.Count == 0)
                  Sw2.WriteLine("Well: " + I.well.ID + "\tIntake: " + I.IDNumber + "\tError: Missing info about screen depth");
                else
                {
                  //Build novanaid
                  string NovanaID = P.IDNumber.ToString() + "_" + I.well.ID.Replace(" ", "") + "_" + I.IDNumber;
                  //Build and add new item
                  _item = new TSItemClass();
                  _item.DataType = ItemDataType.Type_Float;
                  _item.ValueType = ItemValueType.Mean_Step_Accumulated;
                  _item.EumType = eumtype;
                  _item.EumUnit = eumunit;
                  _item.Name = NovanaID;
                  _tso.Add(_item);

                  //Loop the years
                  for (int i = 0; i < NumberOfYears; i++)
                  {
                    //Extractions are not necessarily sorted and the time series may have missing data
                    var k = P.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == Start.Year + i);

                    //First year should be printed twice
                    if (i == 0)
                    {
                      if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                        _item.SetDataForTimeStepNr(1, (float)(k.Value * fractions[i]));
                      else
                        _item.SetDataForTimeStepNr(1, 0F); //Prints 0 if no data available
                    }
                    //If data and the intake is active
                    if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                      _item.SetDataForTimeStepNr(i + 2, (float)(k.Value * fractions[i]));
                    else
                      _item.SetDataForTimeStepNr(i + 2, 0F); //Prints 0 if no data available
                  }

                  //Now add line to text file.
                  StringBuilder Line = new StringBuilder();
                  Line.Append(NovanaID + "\t");
                  Line.Append(I.well.X + "\t");
                  Line.Append(I.well.Y + "\t");
                  Line.Append(I.well.Terrain + "\t");
                  Line.Append("0\t");
                  Line.Append(P.IDNumber + "\t");
                  Line.Append(I.Screens.Max(var => var.TopAsKote) + "\t");
                  Line.Append(I.Screens.Min(var => var.BottomAsKote) + "\t");
                  Line.Append(1 + "\t");
                  Line.Append(dfs0FileName + "\t");
                  Line.Append(itemCount);
                  Sw.WriteLine(Line.ToString());

                  itemCount++;
                }
              }
            }
          }
        }
        TSItem SumItem = new TSItemClass();
        SumItem.DataType = ItemDataType.Type_Float;
        SumItem.ValueType = ItemValueType.Mean_Step_Accumulated;
        SumItem.EumType = eumtype;
        SumItem.EumUnit = eumunit;
        SumItem.Name = "Sum";
        _tsoStat.Add(SumItem);

        TSItem MeanItem = new TSItemClass();
        MeanItem.DataType = ItemDataType.Type_Float;
        MeanItem.ValueType = ItemValueType.Mean_Step_Accumulated;
        MeanItem.EumType = eumtype;
        MeanItem.EumUnit = eumunit;
        MeanItem.Name = "Mean";
        _tsoStat.Add(MeanItem);

        TSItem SumNotUsedItem = new TSItemClass();
        SumNotUsedItem.DataType = ItemDataType.Type_Float;
        SumNotUsedItem.ValueType = ItemValueType.Mean_Step_Accumulated;
        SumNotUsedItem.EumType = eumtype;
        SumNotUsedItem.EumUnit = eumunit;
        SumNotUsedItem.Name = "SumNotUsed";
        _tsoStat.Add(SumNotUsedItem);

        TSItem SumSurfaceWaterItem = new TSItemClass();
        SumSurfaceWaterItem.DataType = ItemDataType.Type_Float;
        SumSurfaceWaterItem.ValueType = ItemValueType.Mean_Step_Accumulated;
        SumSurfaceWaterItem.EumType = eumtype;
        SumSurfaceWaterItem.EumUnit = eumunit;
        SumSurfaceWaterItem.Name = "SumSurfaceWater";
        _tsoStat.Add(SumSurfaceWaterItem);

        for (int i = 0; i < NumberOfYears; i++)
        {
          SumItem.SetDataForTimeStepNr(i + 1, (float)Sum[i]);
          MeanItem.SetDataForTimeStepNr(i + 1, (float)Sum[i] / Pcount);
          SumNotUsedItem.SetDataForTimeStepNr(i + 1, (float)SumNotUsed[i]);
          SumSurfaceWaterItem.SetDataForTimeStepNr(i + 1, (float)SumSurfaceWater[i]);
        }

        _tsoStat.Connection.Save();
        _tso.Connection.Save();
        Sw.Dispose();
        Sw2.Dispose();
      }
コード例 #3
0
      /// <summary>
      /// Writes dfs0 files with head observations for the SelectedIntakes
      /// Only includes data within the period bounded by Start and End
      /// </summary>
      /// <param name="OutputPath"></param>
      public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
      {
        //Create the TSObject
        TSObject _tso = new TSObjectClass();
        TSItem _item = new TSItemClass();
        _item.DataType = ItemDataType.Type_Float;
        _item.ValueType = ItemValueType.Instantaneous;
        _item.EumType = 171;
        _item.EumUnit = 1;
        _item.Name = Intake.ToString();
        _tso.Add(_item);

        DateTime _previousTimeStep = DateTime.MinValue;

        //Select the observations
        var SelectedObs = Intake.HeadObservations.ItemsInPeriod(Start, End);
        int i = 0;

        foreach(var Obs in SelectedObs)
        {
          //Only add the first measurement of the day
          if (Obs.Time != _previousTimeStep)
          {
            _tso.Time.AddTimeSteps(1);
            _tso.Time.SetTimeForTimeStepNr(i + 1, Obs.Time);
            _item.SetDataForTimeStepNr(i + 1, (float)Obs.Value);
          }
          i++;
        }

        //Now write the DFS0.
        if (_tso.Time.NrTimeSteps != 0)
        {
          _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
          _tso.Connection.Save();
        }
      }
コード例 #4
0
ファイル: FileWriters.cs プロジェクト: msruzy/hydronumerics
        /// <summary>
        /// Writes a dfs0 with extraction data for each active intake in every plant.
        /// Also writes the textfile that can be imported by the well editor.
        /// </summary>
        /// <param name="OutputPath"></param>
        /// <param name="Plants"></param>
        /// <param name="Start"></param>
        /// <param name="End"></param>
        public static void WriteExtractionDFS0(string OutputPath, IEnumerable <Plant> Plants, DateTime Start, DateTime End)
        {
            //Create the text file to the well editor.
            StreamWriter Sw  = new StreamWriter(Path.Combine(OutputPath, "WellEditorImport.txt"), false, Encoding.Default);
            StreamWriter Sw2 = new StreamWriter(Path.Combine(OutputPath, "WellsWithMissingInfo.txt"), false, Encoding.Default);

            //Create the TSObject
            TSObject _tso         = new TSObjectClass();
            string   dfs0FileName = Path.Combine(OutputPath, "Extraction.dfs0");

            _tso.Connection.FilePath = dfs0FileName;
            TSItem _item;

            int eumtype = 330;
            int eumunit = 3;


            TSObject _tsoStat = new TSObjectClass();

            _tsoStat.Connection.FilePath = Path.Combine(OutputPath, "ExtractionStat.dfs0");
            Dictionary <int, double> Sum             = new Dictionary <int, double>();
            Dictionary <int, double> SumSurfaceWater = new Dictionary <int, double>();
            Dictionary <int, double> SumNotUsed      = new Dictionary <int, double>();

            int Pcount = 0;

            int NumberOfYears = End.Year - Start.Year + 1;

            //Dummy year because of mean step accumulated
            _tso.Time.AddTimeSteps(1);
            _tso.Time.SetTimeForTimeStepNr(1, new DateTime(Start.Year, 1, 1, 0, 0, 0));

            for (int i = 0; i < NumberOfYears; i++)
            {
                _tso.Time.AddTimeSteps(1);
                _tso.Time.SetTimeForTimeStepNr(i + 2, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));

                _tsoStat.Time.AddTimeSteps(1);
                _tsoStat.Time.SetTimeForTimeStepNr(i + 1, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));
                Sum.Add(i, 0);
                SumSurfaceWater.Add(i, 0);
                SumNotUsed.Add(i, 0);
            }

            int itemCount = 1;

            double[] fractions = new double[NumberOfYears];

            //loop the plants
            foreach (Plant P in Plants)
            {
                double val;
                //Create statistics on surface water for all plants
                for (int i = 0; i < NumberOfYears; i++)
                {
                    if (P.SurfaceWaterExtrations.TryGetValue(Start.AddYears(i), out val))
                    {
                        SumSurfaceWater[i] += val;
                    }
                }

                //Create statistics for plants without intakes
                if (P.PumpingIntakes.Count == 0)
                {
                    //Create statistics on water not assigned
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                        {
                            SumNotUsed[i] += val;
                        }
                    }
                }
                else
                {
                    //Create statistics
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                        {
                            Sum[i] += val;
                        }
                    }
                    Pcount++;


                    //Calculate the fractions based on how many intakes are active for a particular year.
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        fractions[i] = 1.0 / P.PumpingIntakes.Count(var => var.Intake.well.UsedForExtraction & var.Start.Year <= Start.Year + i & var.End.Year >= Start.Year + i);
                    }


                    //Now loop the intakes
                    foreach (PumpingIntake PI in P.PumpingIntakes)
                    {
                        IIntake I = PI.Intake;
                        //Is it an extraction well?
                        if (I.well.UsedForExtraction)
                        {
                            //If there is no screen information we cannot use it.
                            if (I.Screens.Count == 0)
                            {
                                Sw2.WriteLine("Well: " + I.well.ID + "\tIntake: " + I.IDNumber + "\tError: Missing info about screen depth");
                            }
                            else
                            {
                                //Build novanaid
                                string NovanaID = P.IDNumber.ToString() + "_" + I.well.ID.Replace(" ", "") + "_" + I.IDNumber;
                                //Build and add new item
                                _item           = new TSItemClass();
                                _item.DataType  = ItemDataType.Type_Float;
                                _item.ValueType = ItemValueType.Mean_Step_Accumulated;
                                _item.EumType   = eumtype;
                                _item.EumUnit   = eumunit;
                                _item.Name      = NovanaID;
                                _tso.Add(_item);

                                //Loop the years
                                for (int i = 0; i < NumberOfYears; i++)
                                {
                                    //Extractions are not necessarily sorted and the time series may have missing data
                                    var k = P.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == Start.Year + i);

                                    //First year should be printed twice
                                    if (i == 0)
                                    {
                                        if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                                        {
                                            _item.SetDataForTimeStepNr(1, (float)(k.Value * fractions[i]));
                                        }
                                        else
                                        {
                                            _item.SetDataForTimeStepNr(1, 0F); //Prints 0 if no data available
                                        }
                                    }
                                    //If data and the intake is active
                                    if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                                    {
                                        _item.SetDataForTimeStepNr(i + 2, (float)(k.Value * fractions[i]));
                                    }
                                    else
                                    {
                                        _item.SetDataForTimeStepNr(i + 2, 0F); //Prints 0 if no data available
                                    }
                                }

                                //Now add line to text file.
                                StringBuilder Line = new StringBuilder();
                                Line.Append(NovanaID + "\t");
                                Line.Append(I.well.X + "\t");
                                Line.Append(I.well.Y + "\t");
                                Line.Append(I.well.Terrain + "\t");
                                Line.Append("0\t");
                                Line.Append(P.IDNumber + "\t");
                                Line.Append(I.Screens.Max(var => var.TopAsKote) + "\t");
                                Line.Append(I.Screens.Min(var => var.BottomAsKote) + "\t");
                                Line.Append(1 + "\t");
                                Line.Append(dfs0FileName + "\t");
                                Line.Append(itemCount);
                                Sw.WriteLine(Line.ToString());

                                itemCount++;
                            }
                        }
                    }
                }
            }
            TSItem SumItem = new TSItemClass();

            SumItem.DataType  = ItemDataType.Type_Float;
            SumItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumItem.EumType   = eumtype;
            SumItem.EumUnit   = eumunit;
            SumItem.Name      = "Sum";
            _tsoStat.Add(SumItem);

            TSItem MeanItem = new TSItemClass();

            MeanItem.DataType  = ItemDataType.Type_Float;
            MeanItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            MeanItem.EumType   = eumtype;
            MeanItem.EumUnit   = eumunit;
            MeanItem.Name      = "Mean";
            _tsoStat.Add(MeanItem);

            TSItem SumNotUsedItem = new TSItemClass();

            SumNotUsedItem.DataType  = ItemDataType.Type_Float;
            SumNotUsedItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumNotUsedItem.EumType   = eumtype;
            SumNotUsedItem.EumUnit   = eumunit;
            SumNotUsedItem.Name      = "SumNotUsed";
            _tsoStat.Add(SumNotUsedItem);

            TSItem SumSurfaceWaterItem = new TSItemClass();

            SumSurfaceWaterItem.DataType  = ItemDataType.Type_Float;
            SumSurfaceWaterItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumSurfaceWaterItem.EumType   = eumtype;
            SumSurfaceWaterItem.EumUnit   = eumunit;
            SumSurfaceWaterItem.Name      = "SumSurfaceWater";
            _tsoStat.Add(SumSurfaceWaterItem);

            for (int i = 0; i < NumberOfYears; i++)
            {
                SumItem.SetDataForTimeStepNr(i + 1, (float)Sum[i]);
                MeanItem.SetDataForTimeStepNr(i + 1, (float)Sum[i] / Pcount);
                SumNotUsedItem.SetDataForTimeStepNr(i + 1, (float)SumNotUsed[i]);
                SumSurfaceWaterItem.SetDataForTimeStepNr(i + 1, (float)SumSurfaceWater[i]);
            }

            _tsoStat.Connection.Save();
            _tso.Connection.Save();
            Sw.Dispose();
            Sw2.Dispose();
        }
コード例 #5
0
        /// <summary>
        /// Writes dfs0 files with head observations for the SelectedIntakes
        /// Only includes data within the period bounded by Start and End
        /// </summary>
        /// <param name="OutputPath"></param>
        public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
        {
            //Create the TSObject
              TSObject _tso = new TSObjectClass();
              TSItem _item = new TSItemClass();
              _item.DataType = ItemDataType.Type_Float;
              _item.ValueType = ItemValueType.Instantaneous;
              _item.EumType = 171;
              _item.EumUnit = 1;
              _item.Name = Intake.ToString();
              _tso.Add(_item);

              DateTime _previousTimeStep = DateTime.MinValue;

              //Select the observations
              List<ObservationEntry> SelectedObs = Intake.Observations.Where(TSE => InBetween(TSE, Start, End)).ToList<ObservationEntry>();

              SelectedObs.Sort();

              for (int i = 0; i < SelectedObs.Count; i++)
              {
            //Only add the first measurement of the day
            if (SelectedObs[i].Time != _previousTimeStep)
            {
              _tso.Time.AddTimeSteps(1);
              _tso.Time.SetTimeForTimeStepNr(i + 1, SelectedObs[i].Time);
              _item.SetDataForTimeStepNr(i + 1, (float)SelectedObs[i].Value);
            }
              }

              //Now write the DFS0.
              if (_tso.Time.NrTimeSteps != 0)
              {
            _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
            _tso.Connection.Save();
              }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: shobaravi/mikeshewrapper
        static void Main(string[] args)
        {
            string TextFileName="";
            string dfs0FileName="";
            if (args.Length == 0)
            {
              OpenFileDialog OFD = new OpenFileDialog();
              OFD.Title = "Select a text file with discharge data";
              if (DialogResult.OK == OFD.ShowDialog())
                TextFileName = OFD.FileName;
              else
                return;

              SaveFileDialog SFD = new SaveFileDialog();
              SFD.Title = "Select a .dfs0 file or give a new name";
              SFD.Filter = "Known file types (*.dfs0)|*.dfs0";
              SFD.OverwritePrompt = false;
              if (DialogResult.OK == SFD.ShowDialog())
                dfs0FileName = SFD.FileName;
              else
                return;
            }
            else
            {
                TextFileName = args[0];
                dfs0FileName = args[1];
            }

            if (args.Length > 2 || !File.Exists(TextFileName))
            {
                if (DialogResult.Cancel ==
                    MessageBox.Show("This program needs two file names as input. If the file names contain spaces the filename should be embraced by \"\". \n Are these file names correct:? \n" + TextFileName + "\n" + dfs0FileName, "Two many arguments!", MessageBoxButtons.OKCancel))
                    return;
            }

            List<QStation> _stations = new List<QStation>();
            //Loop to read the Q-stations.
            using (StreamReader SR = new StreamReader(TextFileName, Encoding.Default))
            {
                string line;
                while (!SR.EndOfStream)
                {
                    line = SR.ReadLine();
                    if (line.Equals("*"))
                    {
                        QStation qs = new QStation();
                        qs.ReadEntryFromText(SR);
                        _stations.Add(qs);
                    }
                }
            }

            TSObject _data = new TSObjectClass();
            _data.Connection.FilePath = dfs0FileName;
            TSItem I = null;

            //Append to existing file
            if (File.Exists(dfs0FileName))
                _data.Connection.Open();
            else
            {
                //Create new .dfs0-file and list of q-stations
                using (StreamWriter SW = new StreamWriter(Path.Combine(Path.GetDirectoryName(dfs0FileName), "DetailedTimeSeriesImport.txt"),false,Encoding.Default))
                {
                    int k = 1;
                    foreach (var qs in _stations)
                    {
                        //Build the TSITEMS
                        I = new TSItemClass();
                        I.DataType = ItemDataType.Type_Float;
                        I.ValueType = ItemValueType.Instantaneous;
                        I.EumType = 2;
                        I.EumUnit = 1;

                        //Provide an ITEM name following the convention by Anker
                        if (qs.DmuMaalerNr != "")
                            I.Name = qs.DmuMaalerNr;
                        else
                            I.Name = qs.DmuStationsNr.ToString();

                        _data.Add(I);
                        SW.WriteLine(I.Name + "\t" + qs.UTMX + "\t" + qs.UTMY + "\t" + k);
                        k++;
                    }
                }
            }

            // 12 hours have been added in dfs0!
            DateTime LastTimeStep = ((DateTime)_data.Time.EndTime).Subtract(new TimeSpan(12,0,0));

            int TSCount = _data.Time.NrTimeSteps;
            int count;

            DateTime CurrentLastTimeStep = LastTimeStep;

            bool ItemFound = true;

            //Loop the stations from the text-file
            foreach (var qs in _stations)
            {
                qs.Discharge.Sort();
                //See if the station has newer data
                if (qs.Discharge.Last().Time > LastTimeStep)
                {
                    //Find the ITEM. First by DMUMAALERNR
                    try
                    {
                        I = _data.Item(qs.DmuMaalerNr);
                        ItemFound = true;
                    }
                    catch (ArgumentException E)
                    {
                        //Then by DMUSTATIONSNR
                        try
                        {
                            I = _data.Item(qs.DmuStationsNr.ToString());
                            ItemFound = true;
                        }
                        catch (ArgumentException E2)
                        {
                            Console.WriteLine("DMU MÅLER Nr: " + qs.DmuMaalerNr + " eller DMU sted nr: " + qs.DmuStationsNr + " blev ikke fundet i dfs0.filen");
                            ItemFound = false;
                        }
                    }

                    //Write to the item if it exists
                    if (ItemFound)
                    {
                        //Start at the last entry of the original
                        int index = qs.Discharge.FindIndex(var => var.Time > LastTimeStep);
                        count = 0;

                        //Loop all the entries
                        for (int i = index; i < qs.Discharge.Count; i++)
                        {
                            count++;
                            //Check if it is necessary to add timesteps to the tsobject
                            if (qs.Discharge[i].Time > CurrentLastTimeStep)
                            {
                                CurrentLastTimeStep = qs.Discharge[i].Time;
                                _data.Time.AddTimeSteps(1);
                                // 12 hours have been added in dfs0!
                                _data.Time.SetTimeForTimeStepNr(TSCount + count, qs.Discharge[i].Time.AddHours(12));
                            }
                            //Get the index in the time series. We cannot be sure that the times are equidistant in the textfile
                            int tsn = _data.Time.GetTimeStepNrAfter(qs.Discharge[i].Time);
                            I.SetDataForTimeStepNr(tsn, (float)qs.Discharge[i].Value);
                        }
                    }
                }
            }
            _data.Connection.Save();
        }