Example #1
0
        //
        //**********************************************************************************************
        //
        public void ComputeThetas(Double[] aTheta, TAssignmentMethod aMethod, Int32 aSteps)
        {
            TThetaPoint MyTheta;
              Theta.Clear();
              Double XReal;
              Double YReal;
              Steps = aSteps;
              Double dX = 2.0 / Steps;
              Double dY = 2.0 / Steps;

              Double X = -1.0 - dX;
              Double Y = -1.0 - dX;

              Double N0 = 0.0;
              Double N1 = 0.0;
              Double N2 = 0.0;
              Double N3 = 0.0;

              Double V0 = 0.0;
              Double V1 = 0.0;
              Double V2 = 0.0;
              Double V3 = 0.0;

              Double Value = 0.0;

              for (Int32 i = 0; i <= Steps; i++)
              {
            X = X + dX;
            Y = -1.0 - dY;
            for (Int32 j = 0; j <= Steps; j++)
            {
              Y = Y + dY;
              XReal = Alpha[0] + Alpha[1] * X + Alpha[2] * Y + Alpha[3] * X * Y;
              YReal = Beta[0] + Beta[1] * X + Beta[2] * Y + Beta[3] * X * Y;
              MyTheta = new TThetaPoint();
              MyTheta.X = XReal;
              MyTheta.Y = YReal;

              if (aMethod == TAssignmentMethod.NearestNeighbour)
              {
            Double MinDist = 1.0e36;
            Int32 IMin = -1;
            for (Int32 k = 0; k <= 3; k++)
            {
              Double d = Math.Sqrt((XReal - Node[k].X) * (XReal - Node[k].X) + (YReal - Node[k].Y) * (YReal - Node[k].Y));
              if (d < MinDist)
              {
                MinDist = d;
                IMin = k;
              }
            }
            Value = aTheta[Node[IMin].Id - 1];
              }
              else
              {
            N0 = 0.25 * (1.0 + X * (-1.0)) * (1.0 + Y * (-1.0));
            N1 = 0.25 * (1.0 + X * (1.0)) * (1.0 + Y * (-1.0));
            N2 = 0.25 * (1.0 + X * (1.0)) * (1.0 + Y * (1.0));
            N3 = 0.25 * (1.0 + X * (-1.0)) * (1.0 + Y * (1.0));

            V0 = aTheta[Node[0].Id - 1];
            V1 = aTheta[Node[1].Id - 1];
            V2 = aTheta[Node[2].Id - 1];
            V3 = aTheta[Node[3].Id - 1];

            Value = N0 * V0 + N1 * V1 + N2 * V2 + N3 * V3;
              }
              MyTheta.Theta = Value;

              Theta.Add(MyTheta);
            }
              }
        }
Example #2
0
        //
        //**********************************************************************************************
        //
        public Boolean InitializeControl(System.Windows.Forms.PictureBox aPicture,
                    System.Windows.Forms.RichTextBox aLog,
                    System.Windows.Forms.ProgressBar aTimeBar,
                    System.Windows.Forms.ProgressBar aPointBar,
                    System.Windows.Forms.Button aBackgroundButton,
                    System.Windows.Forms.Button aTextButton,
                    System.Windows.Forms.Button aPrecipitationButton,
                    System.Windows.Forms.Button aIrrigationButton,
                    String aFile,
                    String aPrecipitationFile,
                    Boolean aIrrigationRequired,
                    String aIrrigationFile,
                    String aPPTFile,
                    Boolean aPPTRequired,
                    String aOutputDir,
                    Steema.TeeChart.TChart achrtPrec1)
        {
            Boolean success = false;
              if (!Directory.Exists(aOutputDir))
              {
            if (MessageBox.Show("Output dir " + aOutputDir + " does not exist. Create it?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
              Directory.CreateDirectory(aOutputDir);
            }
              }
              if (Directory.Exists(aOutputDir))
              {
            try
            {
              Running = false;
              brTimes = aTimeBar;
              PrecipitationFile = aPrecipitationFile;
              brPoints = aPointBar;
              LogBox = aLog;
              OutputDir = aOutputDir;
              LogBox.Clear();
              LogBox.AppendText("Started at " + DateTime.Now.ToString() + "\n");
              Top = new List<TPoint>();
              Bottom = new List<TPoint>();
              Left = new List<TPoint>();
              Right = new List<TPoint>();
              IrrigationRequired = aIrrigationRequired;
              IrrigationFile = aIrrigationFile;
              PPTFile = aPPTFile;
              PPTRequired = aPPTRequired;
              chrtPrec1 = achrtPrec1;
              PlotToShow = new List<TPlotToShow>();

              if (PPTRequired)
              {
            PPT = new TPPT();
              }

              DataManager.SaveToIniFile(aFile, aPrecipitationFile, aIrrigationFile, aOutputDir, aIrrigationRequired, aPPTRequired, aPPTFile);
              DataManager.ReadExcelFile(aFile);

              if (DataManager.ExcelIsAvailable)
              {

            SetDateFormat();

            TotalBitmap = new Bitmap(800, 600);
            //        TotalBitmap.SetResolution(300, 300);
            DataManager.ReadContourSheet(Top, Right, Bottom, Left);
            MyDrawing = new TDrawing(BackgroundColor, TextColor);
            //      MyDrawing.DrawContours(Top, Right, Bottom, Left);
            MyGraph = Graphics.FromImage(TotalBitmap);

            Int32 NumberOfPlots = DataManager.ReadNumberOfPlots();

            AssignmentMethod = DataManager.ReadAssignmentMethod();

            Plot = new List<TPlot>();
            for (Int32 i = 0; i < NumberOfPlots; i++)
            {
              TPlot MyPlot = new TPlot(i);
              MyPlot.AddBoundaries(Top, Bottom, Left, Right);
              MyPlot.AssignmentMethod = AssignmentMethod;

              Plot.Add(MyPlot);
            }

            DataManager.ReadPlotDescription(Plot);
            DataManager.ReadVisualization(PlotToShow);

            DistributePlots();

            for (Int32 i = 0; i < NumberOfPlots; i++)
            {
              DataManager.ReadNodes(Plot[i].Node, i);
              DataManager.ReadElements(Plot[i].Node, Plot[i].Element, i);
              DataManager.ReadVirtualNodes(Plot[i].VirtualNode, i);
            }

            foreach (TPlotToShow MyPlot in PlotToShow)
            {
              Plot[MyPlot.PlotId].PrepareAndDrawGrid(MyPlot.ItemToVisualize);
            }

            DefineFirstAndLastNode();

            CreateTotalBitmap(false);

            SaveGraph(OutputDir, -100);

            MoistureClass = new List<TMoistureClass>();
            DerivedClass = new List<TDerivedClass>();
            DataManager.ReadDerivativeTables(Plot);
            DataManager.ReadMoistureClasses(MoistureClass, DerivedClass);

            MyMoistureLegend = new TLegend(Color.Black, Color.White);
            MyMoistureLegend.SetDrawingArea(800, 600);
            MyMoistureLegend.DrawLegend(MoistureClass);

            MyDerivedLegend = new TLegend(Color.Black, Color.White);
            MyDerivedLegend.SetDrawingArea(800, 600);
            MyDerivedLegend.DrawDerivedLegend(DerivedClass);

            String FileName = SaveGraph(OutputDir, -10);
            if (PPTRequired)
            {
              PPT.AddPictureToSlide(FileName);
            }
            FileName = SaveGraph(OutputDir, -11);
            if (PPTRequired)
            {
              PPT.AddPictureToSlide(FileName);
            }

            MoistureContent = DataManager.ReadMoistureContents();

            FindFirstAndLastDay();

            PrecipitationInterval = DataManager.ReadPInterval();

            ReadColors(aBackgroundButton, aTextButton, aPrecipitationButton, aIrrigationButton);

            DataManager.CloseExcelFile();

            Precipitation = DataManager.ReadPrecipitation(PrecipitationFile, FirstDay, LastDay);
            if (IrrigationRequired)
            {
              Irrigation = DataManager.ReadIrrigation(IrrigationFile);
            }

            DataManager.QuitExcel();

            chrtPrec2 = new Steema.TeeChart.TChart();

            // precipitation
            Steema.TeeChart.Styles.Bar NewSeries = new Steema.TeeChart.Styles.Bar();
            NewSeries.XValues.DateTime = true;
            NewSeries.Color = PrecipitationColor;
            NewSeries.Marks.Visible = false;
            NewSeries.Pen.Visible = false;
            chrtPrec2.Series.Add(NewSeries);

            // irrigation
            NewSeries = new Steema.TeeChart.Styles.Bar();
            NewSeries.XValues.DateTime = true;
            NewSeries.Color = IrrigationColor;
            NewSeries.Marks.Visible = false;
            NewSeries.Pen.Visible = false;
            chrtPrec2.Series.Add(NewSeries);

            // line
            Steema.TeeChart.Styles.Line Line = new Steema.TeeChart.Styles.Line();
            Line.Color = Color.Red;
            Line.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;
            Line.XValues.DateTime = true;
            chrtPrec2.Axes.Right.Automatic = false;
            chrtPrec2.Axes.Right.Minimum = 0.0;
            chrtPrec2.Axes.Right.Maximum = 1.0;
            chrtPrec2.Axes.Right.Visible = false;
            chrtPrec2.Series.Add(Line);

            // clear
            chrtPrec1.Series[0].Clear();
            chrtPrec1.Series[1].Clear();
            chrtPrec1.Series[2].Clear();
            chrtPrec2.Series[0].Clear();
            chrtPrec2.Series[1].Clear();
            chrtPrec2.Series[2].Clear();

            ShowPrecipitation(1);
            ShowPrecipitation(2);

            //      MyDrawing.SaveGraph(OutputDir, -1);
              }
              LogBox.AppendText(@"Data read at " + DateTime.Now.ToString());
              success = true;
            }
            catch (Exception e)
            {
              String ErrorMessage = @"Error in input data : " + e.Message;
              MessageBox.Show(ErrorMessage);
              LogBox.AppendText(ErrorMessage);
            }
              }
              return success;
        }
Example #3
0
        //
        //**********************************************************************************************
        //
        public Double ThetaAtXY(Double[] aTheta, TAssignmentMethod aMethod, Double aX, Double aY)
        {
            Double N0 = 0.0;
              Double N1 = 0.0;
              Double N2 = 0.0;
              Double N3 = 0.0;

              Double V0 = 0.0;
              Double V1 = 0.0;
              Double V2 = 0.0;
              Double V3 = 0.0;

              Double Value = 0.0;

              if (aMethod == TAssignmentMethod.NearestNeighbour)
              {
            Double MinDist = 1.0e36;
            Int32 IMin = -1;
            for (Int32 k = 0; k <= 3; k++)
            {
              Double d = Math.Sqrt((aX - Node[k].X) * (aX - Node[k].X) + (aY - Node[k].Y) * (aY - Node[k].Y));
              if (d < MinDist)
              {
            MinDist = d;
            IMin = k;
              }
            }
            Value = aTheta[Node[IMin].Id - 1];
              }
              else
              {
            // global to local
            Double Xlocal = Gamma[0] + Gamma[1] * aX + Gamma[2] * aY + Gamma[3] * aX * aY;
            Double Ylocal = Delta[0] + Delta[1] * aX + Delta[2] * aY + Delta[3] * aX * aY;

            N0 = 0.25 * (1.0 + Xlocal * (-1.0)) * (1.0 + Ylocal * (-1.0));
            N1 = 0.25 * (1.0 + Xlocal * (1.0)) * (1.0 + Ylocal * (-1.0));
            N2 = 0.25 * (1.0 + Xlocal * (1.0)) * (1.0 + Ylocal * (1.0));
            N3 = 0.25 * (1.0 + Xlocal * (-1.0)) * (1.0 + Ylocal * (1.0));

            V0 = aTheta[Node[0].Id - 1];
            V1 = aTheta[Node[1].Id - 1];
            V2 = aTheta[Node[2].Id - 1];
            V3 = aTheta[Node[3].Id - 1];

            Value = N0 * V0 + N1 * V1 + N2 * V2 + N3 * V3;
              }
              return Value;
        }