/// <summary>
      /// Reads in the wells defined in detailed timeseries input section
      /// </summary>
      /// <param name="Mshe"></param>
      public static IEnumerable<IWell> ReadInDetailedTimeSeries(Model Mshe)
      {
        MikeSheWell CurrentWell;
        IIntake CurrentIntake;
        TSObject _tso = null;

        foreach (var dt in Mshe.Input.MIKESHE_FLOWMODEL.StoringOfResults.DetailedTimeseriesOutput.Item_1s)
        {
          CurrentWell = new MikeSheWell(dt.Name);
          CurrentWell.X = dt.X;
          CurrentWell.Y = dt.Y;
          CurrentWell.UsedForExtraction = false;
          CurrentIntake = CurrentWell.AddNewIntake(1);
          Screen sc = new Screen(CurrentIntake);
          sc.DepthToTop = dt.Z;
          sc.DepthToBottom = dt.Z;

          CurrentWell.Row = Mshe.GridInfo.GetRowIndex(CurrentWell.X);
          CurrentWell.Column = Mshe.GridInfo.GetColumnIndex(CurrentWell.Y);

          CurrentWell.Terrain = Mshe.GridInfo.SurfaceTopography.Data[CurrentWell.Row, CurrentWell.Column];

          //Read in observations if they are included
          if (dt.InclObserved == 1)
          {
            if (_tso == null || _tso.Connection.FilePath != dt.TIME_SERIES_FILE.FILE_NAME)
            {
              _tso = new TSObjectClass();
              _tso.Connection.FilePath = dt.TIME_SERIES_FILE.FILE_NAME;
              _tso.Connection.Open();
            }

            //Loop the observations and add
            for (int i = 1; i <= _tso.Time.NrTimeSteps; i++)
            {
              CurrentIntake.HeadObservations.Items.Add(new TimestampValue((DateTime)_tso.Time.GetTimeForTimeStepNr(i), (float)_tso.Item(dt.TIME_SERIES_FILE.ITEM_NUMBERS).GetDataForTimeStepNr(i)));
            }
          }
          yield return CurrentWell;
        }
      }
    /// <summary>
    /// Reads in head observations from txt file with this format.
    /// "WellID X Y Z Head  Date  Layer". Separated with tabs. Layer is optional
    /// </summary>
    /// <param name="LSFileName"></param>
    public Dictionary<string, MikeSheWell> ReadFromLSText(string LSFileName)
    {
      Dictionary<string, MikeSheWell> Wells = new Dictionary<string, MikeSheWell>();
      //Sets the output file name for subsequent writing
      string path = Path.GetDirectoryName(LSFileName);
      string FileName = Path.GetFileNameWithoutExtension(LSFileName);
      _baseOutPutFileName = Path.Combine(path, FileName);

      //Now read the input
      using (StreamReader SR = new StreamReader(LSFileName))
      {
        //Reads the HeadLine
        string line = SR.ReadLine();
        string[] s;
        MikeSheWell OW;

        while ((line = SR.ReadLine()) != null)
        {
          s = line.Split('\t');

          //Check that s has correct lengt and does not consist of empty entries
          if (s.Length > 5 & s.Aggregate<string>((a,b)=>a+b)!="")
          {
            try
            {
              LsIntake I = null;
              //If the well has not already been read in create a new one
              if (!Wells.TryGetValue(s[0], out OW))
              {
                OW = new MikeSheWell(s[0]);
                I = new LsIntake(OW, 1);
                OW.AddIntake(I);
                Wells.Add(OW.ID, OW);
                OW.X = double.Parse(s[1]);
                OW.Y = double.Parse(s[2]);

                //Layer is provided directly. Calculate Z
                if (s.Length >= 7 && s[6] != "")
                {
                  OW.Layer = _numberOfLayers - int.Parse(s[6]);
                }
                //Use the Z-coordinate
                else
                {
                  OW.Depth = double.Parse(s[3]);
                  OW.Layer = -3;
                }
              }

              if (I == null)
                I = OW.Intakes.First() as LsIntake;

              //Now add the observation
              I.Observations.Add(new Observation(DateTime.ParseExact(s[5], new string[] {"dd-MM-yyyy", "d-MM-yyyy", "d-M-yyyy", "dd-M-yyyy"},null, System.Globalization.DateTimeStyles.None), double.Parse(s[4]),OW));
            }
            catch (FormatException e)
            {
              MessageBox.Show("Error reading this line:\n\n" + line +"\n\nFrom file: "+ LSFileName + "\n\nLine skipped!", "Format error!");
            }
          }
        }
      } //End of streamreader
      return Wells;
    }
 public Observation(DateTime time, double Value, MikeSheWell well)
 {
   this.Time = time;
   this.Value = Value;
   Well = well;
 }