public void Initialize(IArgument[] properties)
    {
      MsheOrg.Initialize(properties);

      string mshefilename = System.IO.Path.Combine(properties.First(a => a.Key == "SetupPath").Value, properties.First(a => a.Key == "SetupFileName").Value);

      Model mshe = new Model(mshefilename);

      List<double> InnerXValues= new List<double>();
      List<double> InnerYValues = new List<double>();

      int k=0;
        for(int j=0;j<mshe.GridInfo.NumberOfColumns;j++)
          for (int i = 0; i < mshe.GridInfo.NumberOfRows; i++)
          {
          if (mshe.GridInfo.ModelDomainAndGrid.Data[i, j] == 1)
          {
            InnerXValues.Add(mshe.GridInfo.GetXCenter(j));
            InnerYValues.Add(mshe.GridInfo.GetYCenter(i));
            InnerIdeces.Add(k);
            k++;
          }
          else if (mshe.GridInfo.ModelDomainAndGrid.Data[i, j] == 2)
            k++;
        }


        DHI.OpenMI.MikeShe.BaseGridElementSet NewBaseGrid = new DHI.OpenMI.MikeShe.BaseGridElementSet(new DHI.MikeShe.Engine.BaseGrid(InnerXValues.Count, InnerXValues.ToArray(), InnerYValues.ToArray(), mshe.GridInfo.GridSize,0));

      mshe.Dispose();
      for (int i = 0; i < MsheOrg.OutputExchangeItemCount; i++)
      {
        var org = MsheOrg.GetOutputExchangeItem(i);

        if (org.ElementSet.ID == "BaseGrid")
        {
          OutputExchangeItem onew = new OutputExchangeItem();
          onew.Quantity = org.Quantity;
          onew.ElementSet = NewBaseGrid;
          for (int j = 0; j < org.DataOperationCount; j++)
          {
            onew.AddDataOperation(org.GetDataOperation(j));
          }
          OutputExchangeItems.Add(onew);
        }
        else
        {
          OutputExchangeItems.Add(org);
        }
      }
    }
Beispiel #2
0
        public override void Initialize(System.Collections.Hashtable properties)
        {
            string configFile = null;

            //Get Config file directory from .omi file
            if (properties.ContainsKey("ConfigFile"))
            {
                configFile = (string)properties["ConfigFile"];
            }

            //Set variables
            SetVariablesFromConfigFile(configFile);
            SetValuesTableFields();

            //get input exchange item attributes
            int num_inputs           = this.GetInputExchangeItemCount();
            InputExchangeItem input0 = this.GetInputExchangeItem(num_inputs - 5);

            input_elementset0 = input0.ElementSet.ID;
            input_quantity0   = input0.Quantity.ID;
            InputExchangeItem input1 = this.GetInputExchangeItem(num_inputs - 4);

            input_elementset1 = input1.ElementSet.ID;
            input_quantity1   = input1.Quantity.ID;
            InputExchangeItem input2 = this.GetInputExchangeItem(num_inputs - 3);

            input_elementset2 = input2.ElementSet.ID;
            input_quantity2   = input2.Quantity.ID;
            InputExchangeItem input3 = this.GetInputExchangeItem(num_inputs - 2);

            input_elementset3 = input3.ElementSet.ID;
            input_quantity3   = input3.Quantity.ID;
            InputExchangeItem input4 = this.GetInputExchangeItem(num_inputs - 1);

            input_elementset4 = input4.ElementSet.ID;
            input_quantity4   = input4.Quantity.ID;

            //get output exchange item attributes
            int num_outputs           = this.GetOutputExchangeItemCount();
            OutputExchangeItem output = this.GetOutputExchangeItem(num_outputs - 1);

            output_elementset = output.ElementSet.ID;
            output_quantity   = output.Quantity.ID;

            // --- setup elementValues DataTable to store element attributes from elements.shp
            _elementValues.Columns.Add("Gauge_IDs", typeof(double));
            _elementValues.Columns.Add("Longitude", typeof(double));
            _elementValues.Columns.Add("Latitude", typeof(double));
            _elementValues.Columns.Add("Alpha", typeof(double));
            _elementValues.Columns.Add("Atm_Coeff", typeof(double));
            _elementValues.Columns.Add("Elevation", typeof(double));

            //Get shapefile path
            XmlDocument doc = new XmlDocument();

            doc.Load(configFile);
            XmlElement root          = doc.DocumentElement;
            XmlNode    elementSet    = root.SelectSingleNode("//InputExchangeItem//ElementSet");
            string     shapefilePath = elementSet["ShapefilePath"].InnerText;

            //Get watershed properties from elements.shp
            SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("elements_layer");
            myLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(shapefilePath);
            myLayer.DataSource.Open();

            for (uint i = 0; i < myLayer.DataSource.GetFeatureCount(); i++)
            {
                SharpMap.Data.FeatureDataRow feat = myLayer.DataSource.GetFeature(i);
                //DataTable att = feat.Table;

                object GaugeId   = feat.ItemArray[feat.Table.Columns.IndexOf("GaugeIDs")];
                object Longitute = feat.ItemArray[feat.Table.Columns.IndexOf("X")];
                object Latitude  = feat.ItemArray[feat.Table.Columns.IndexOf("Y")];
                object Alpha     = feat.ItemArray[feat.Table.Columns.IndexOf("Alpha")];
                object Coeff_a   = feat.ItemArray[feat.Table.Columns.IndexOf("Coeff_a")];
                object Elevation = feat.ItemArray[feat.Table.Columns.IndexOf("Elevation")];
                _elementValues.LoadDataRow(new object[] { GaugeId, Longitute, Latitude, Alpha, Coeff_a, Elevation }, true);
            }
        }
 public void Init()
 {
     exchangeItem = new OutputExchangeItem();
     exchangeItem.AddDataOperation(new DataOperation("DataOperation"));
 }
Beispiel #4
0
        private OutputExchangeItem addDataOperations(OutputExchangeItem outputexchangeitem)
        {
            //Add dataoperations to outputexchangeitems
            ElementMapper elementMapper  = new ElementMapper();
            ArrayList     dataOperations = new ArrayList();

            dataOperations = elementMapper.GetAvailableDataOperations(outputexchangeitem.ElementSet.ElementType);
            bool spatialDataOperationExists;
            bool linearConversionDataOperationExists;
            bool smartBufferDataOperationExists;

            foreach (IDataOperation dataOperation in dataOperations)
            {
                spatialDataOperationExists = false;
                foreach (IDataOperation existingDataOperation in outputexchangeitem.DataOperations)
                {
                    if (dataOperation.ID == existingDataOperation.ID)
                    {
                        spatialDataOperationExists = true;
                    }
                }

                if (!spatialDataOperationExists)
                {
                    outputexchangeitem.AddDataOperation(dataOperation);
                }
            }

            IDataOperation linearConversionDataOperation = new LinearConversionDataOperation();

            linearConversionDataOperationExists = false;
            foreach (IDataOperation existingDataOperation in outputexchangeitem.DataOperations)
            {
                if (linearConversionDataOperation.ID == existingDataOperation.ID)
                {
                    linearConversionDataOperationExists = true;
                }
            }

            if (!linearConversionDataOperationExists)
            {
                outputexchangeitem.AddDataOperation(new LinearConversionDataOperation());
            }

            IDataOperation smartBufferDataOperaion = new SmartBufferDataOperation();

            smartBufferDataOperationExists = false;
            foreach (IDataOperation existingDataOperation in outputexchangeitem.DataOperations)
            {
                if (smartBufferDataOperaion.ID == existingDataOperation.ID)
                {
                    smartBufferDataOperationExists = true;
                }
            }

            if (!smartBufferDataOperationExists)
            {
                outputexchangeitem.AddDataOperation(new SmartBufferDataOperation());
            }

            return(outputexchangeitem);
        }
Beispiel #5
0
        private OutputExchangeItem buildExchangeItemFromFolder(string folder)
        {
            //The routine will construct an OpenMI exchange item from a folder of WaterML files.
            //assumptions: (1) all files within the folder are waterML files
            //             (2) all files within folder have the same variable element
            //
            // --- MAPPING BETWEEN OPENMI AND WATERML
            // Qunatity <-- from the first file in the directory
            //   ID [REQUIRED] = WaterML's variableParam element inner text
            //   Description [optional] = WaterML's variableName element inner text
            //   ValueType [hard coded] = Scalar
            //   Unit
            //     ID [optional]= WaterML's units element attribute unitsAbbreviation
            //     ConversionFactortoSI [optional] = not in WaterML
            //     ConverstionOffsettoSI [optional] = not in WaterML
            //   Dimension
            //     Power [optional] = not in WaterML
            // ElementSet
            //   ID [REQUIRED] = folder name
            //   Description [REQUIRED] = folder relative path
            //   ElementType [hard coded] = XYPoint or IDBased
            //   Element
            //     ID [optional]= WaterML's SiteCode element inner text [changing to locationParam]
            //     Vertex
            //       X = WaterML's longitude element inner text
            //       Y = WaterML's latitude element inner text
            //   ...
            // TimeHorizon <-- union of all file-level time horizons

            //get list of files within the folder
            string[] files = Directory.GetFiles(folder);

            //load the first file in the directory as an XML document
            XmlDocument xmldoc = new XmlDocument();

            // load the first xml file in the directory
            StreamReader sr = new StreamReader(files[0]);

            //deserialize
            XmlSerializer          xml_reader = new XmlSerializer(typeof(TimeSeriesResponseType));
            TimeSeriesResponseType tsr        = (TimeSeriesResponseType)xml_reader.Deserialize(sr);

            Quantity           quantity           = new Quantity();
            Unit               unit               = new Unit();
            Dimension          dimension          = new Dimension();
            ElementSet         elementset         = new ElementSet();
            OutputExchangeItem outputexchangeitem = new OutputExchangeItem();

            //Quantity ID -- REQUIRED
            try { quantity.ID = tsr.queryInfo.criteria.variableParam; }
            catch { throw new Exception("waterML document must contain a variableParam element"); }

            //Quantity Description -- optional
            try { quantity.Description = tsr.timeSeries.variable.variableName; }
            catch { quantity.Description = ""; }

            //Quantity Variable Type -- hard coded
            quantity.ValueType = global::OpenMI.Standard.ValueType.Scalar;

            //Unit ID -- optional
            try { unit.ID = tsr.timeSeries.variable.units.unitsAbbreviation; }
            catch { unit.ID = ""; }

            //Unit Converstion Factor to SI
            //TODO WaterML does not include conversion factors to SI
            //unit.ConversionFactorToSI = 0;

            //Unit Converstion Offset to SI
            //TODO WaterML does not include conversion offest to SI
            //unit.OffSetToSI = 0;

            quantity.Unit = unit;

            //Dimension Powers -- optional
            //TODO WaterML does not include dimension info for units
            //Examples below ...
            //dimension.SetPower(DimensionBase.Length, 3);
            //dimension.SetPower(DimensionBase.Time, -1);

            quantity.Dimension = dimension;

            //ElementSet ID -- folder name
            elementset.ID = new DirectoryInfo(folder).Name;

            //ElementSet Description -- folder relative path
            elementset.Description = folder;

            //ElementSet ElementType -- hard coded
            elementset.ElementType = ElementType.XYPoint;

            // -------------------------------------------------------------------
            // The remaining objects require access to all files in the directory.
            // -------------------------------------------------------------------

            foreach (string fileName in files)
            {
                //load the first file in the directory as an XML document
                sr  = new StreamReader(fileName);
                tsr = (TimeSeriesResponseType)xml_reader.Deserialize(sr);

                Element element = new Element();
                Vertex  vertex  = new Vertex();

                //Element ID -- optional
                try { element.ID = tsr.queryInfo.criteria.locationParam; }
                catch { element.ID = ""; }

                //Vertex X and Y -- optional
                //tsr.timeSeries. TODO fix this.
                //if (xml_location != null && xml_location["longitude"] != null && xml_location["latitude"] != null)
                //{
                //    vertex.x = Convert.ToDouble(xml_location["longitude"].InnerText);
                //    vertex.y = Convert.ToDouble(xml_location["latitude"].InnerText);
                //}
                //else { vertex.x = double.NaN; vertex.y = double.NaN; elementset.ElementType = ElementType.IDBased; }
                element.AddVertex(vertex);

                elementset.AddElement(element);

                //TimeHorizon -- REQUIRED
//if (_earliestInputTime == 0.0)
//               {
                string beginDateTimeString;
                try { beginDateTimeString = tsr.queryInfo.criteria.timeParam.beginDateTime; }
                catch { throw new Exception("waterML document must contain a beginDateTime element"); }

                string endDateTimeString;
                try { endDateTimeString = tsr.queryInfo.criteria.timeParam.endDateTime; }
                catch { throw new Exception("waterML document must contain an endDateTime element"); }

                DateTime beginDateTime       = Convert.ToDateTime(beginDateTimeString);
                DateTime endDateTime         = Convert.ToDateTime(endDateTimeString);
                double   beginDateTimeDouble = CalendarConverter.Gregorian2ModifiedJulian(beginDateTime);
                double   endDateTimeDouble   = CalendarConverter.Gregorian2ModifiedJulian(endDateTime);

                //update time horizon to be inclusive of this time horizon
                if (_earliestInputTime == 0.0)
                {
                    _earliestInputTime = beginDateTimeDouble;
                }
                if (beginDateTimeDouble < _earliestInputTime)
                {
                    _earliestInputTime = beginDateTimeDouble;
                }
                ;
                if (endDateTimeDouble > _latestInputTime)
                {
                    _latestInputTime = endDateTimeDouble;
                }
                ;
                //              }
            }
            outputexchangeitem.Quantity   = quantity;
            outputexchangeitem.ElementSet = elementset;

            // add data operations and return
            return(addDataOperations(outputexchangeitem));
        }
Beispiel #6
0
        public void Initialize(IArgument[] properties)
        {
            // The code loops through the WaterMLdb and builds OpenMI exchange items based on
            // the folder contents. It is assumed that the WaterMLdb has the following directory
            // structure:
            //
            // - db [Folder]
            //   - exchange_item_1_name [Folder]
            //     - watermlfile1.xml [File]
            //     - watermlfile2.xml [File]
            //     ...
            //   - exchange_item_2_name
            //     - watermlfile1.xml
            //     - watermlfile2.xml
            //     ...
            //   ...
            //
            // All WaterML files within an exchange item folder must have the same quantity because
            // OpenMI defines an exchange item as being for one quantity and one or more locations.
            // A WaterML file contains only one "time series", that is measurements of one variable
            // through time at only one location.


            //extract argument(s) from OMI file
            foreach (IArgument property in properties)
            {
                if (property.Key == "WaterMLdb")
                {
                    _dbPath = property.Value;
                }
                ;
                //default value for relationFactor is 1;
                if (property.Key == "Relaxation")
                {
                    _smartBuffer.RelaxationFactor = Convert.ToDouble(property.Value);
                }
                ;
            }

            _fullPath = Directory.GetCurrentDirectory();



            string[] subdirs = Directory.GetDirectories(_dbPath);
            foreach (string subdir in subdirs)
            {
                try
                {
                    OutputExchangeItem exchangeitem = buildExchangeItemFromFolder(subdir);
                    if (exchangeitem != null)
                    {
                        _outputExchangeItems.Add(exchangeitem);
                    }
                    ;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Could not read exchange item directory " + subdir + ". " +
                                    "Error message: " + ex.Message);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// This method is used to perform actions prior to model simulation
        /// </summary>
        /// <param name="properties"></param>
        public override void Initialize(System.Collections.Hashtable properties)
        {
            //Get config file path defined in sample.omi
            string configFile = (string)properties["ConfigFile"];

            //set OpenMI internal variables
            this.SetVariablesFromConfigFile(configFile);
            
            // initialize a data structure to hold results
            this.SetValuesTableFields();

            //save the time step (defined within the config.xml)
            _timestep = this.GetTimeStep();

            //save input exchange item info 
            InputExchangeItem input = this.GetInputExchangeItem(0);
            _input_elementset = input.ElementSet.ID;
            _input_quantity = input.Quantity.ID;

            //save output exchange item info 
            OutputExchangeItem output = this.GetOutputExchangeItem(0);
            _output_elementset = output.ElementSet.ID;
            _output_quantity = output.Quantity.ID;

            //Note: this can region can be omitted if a shapefile is specified in config.xml
            #region Manually Define Element Set

            //Get the input and output element sets from the SMW
            ElementSet out_elem = (ElementSet)this.Outputs[0].ElementSet;
            ElementSet in_elem  = (ElementSet)this.Inputs[0].ElementSet;

            //Set some ElementSet properties
            out_elem.ElementType    = OpenMI.Standard.ElementType.XYPoint;
            in_elem.ElementType     = OpenMI.Standard.ElementType.XYPoint;

            //Create elements e1, e2 and e3
            Element e1  = new Element();
            Vertex v1   = new Vertex(1, 1, 0);
            e1.AddVertex(v1);

            Element e2  = new Element();
            Vertex v2   = new Vertex(1, 5, 0);
            e2.AddVertex(v2);

            Element e3  = new Element();
            Vertex v3   = new Vertex(5, 5, 0);
            e2.AddVertex(v3);

            //add these elements to the input and output element sets
            out_elem.AddElement(e1);
            out_elem.AddElement(e2);
            out_elem.AddElement(e3);
            in_elem.AddElement(e1);
            in_elem.AddElement(e2);
            in_elem.AddElement(e3);

            

            #endregion


            //Do some Calculations prior to simulation
            for (int i = 0; i < in_elem.Elements.Length; i++)
                _seeds.Add(_rndNum.Next());
        }
Beispiel #8
0
        public void Initialize(System.Collections.Hashtable properties)
        {
            if (properties.ContainsKey("ModelID"))
            {
                _modelID = (string)properties["ModelID"];
            }

            if (properties.ContainsKey("TimeStepLength"))
            {
                _timeStepLength = Convert.ToDouble((string)properties["TimeStepLength"]);
            }

            // -- create a flow quanitity --
            Dimension flowDimension = new Dimension();

            flowDimension.SetPower(DimensionBase.Length, 3);
            flowDimension.SetPower(DimensionBase.Time, -1);
            Unit     literPrSecUnit = new Unit("LiterPrSecond", 0.001, 0, "Liters pr Second");
            Quantity flowQuantity   = new Quantity(literPrSecUnit, "Flow", "Flow", global::OpenMI.Standard.ValueType.Scalar, flowDimension);

            // -- create leakage quantity --
            Quantity leakageQuantity = new Quantity(literPrSecUnit, "Leakage", "Leakage", global::OpenMI.Standard.ValueType.Scalar, flowDimension);

            // -- create and populate elementset to represente the whole river network --
            ElementSet fullRiverElementSet = new ElementSet("WholeRiver", "WholeRiver", ElementType.XYPolyLine, new SpatialReference("no reference"));

            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                Element element = new Element();
                element.ID = "Branch:" + i.ToString();
                element.AddVertex(new Vertex(_xCoordinate[i], _yCoordinate[i], -999));
                element.AddVertex(new Vertex(_xCoordinate[i + 1], _yCoordinate[i + 1], -999));
                fullRiverElementSet.AddElement(element);
            }

            // --- populate input exchange items for flow to individual nodes ---
            for (int i = 0; i < _numberOfNodes; i++)
            {
                Element element = new Element();
                element.ID = "Node:" + i.ToString();
                ElementSet elementSet = new ElementSet("Individual nodes", "Node:" + i.ToString(), ElementType.IDBased, new SpatialReference("no reference"));
                elementSet.AddElement(element);
                InputExchangeItem inputExchangeItem = new InputExchangeItem();
                inputExchangeItem.ElementSet = elementSet;
                inputExchangeItem.Quantity   = flowQuantity;

                _inputExchangeItems.Add(inputExchangeItem);
            }

            // --- Populate input exchange item for flow to the whole georeferenced river ---
            InputExchangeItem wholeRiverInputExchangeItem = new InputExchangeItem();

            wholeRiverInputExchangeItem.ElementSet = fullRiverElementSet;
            wholeRiverInputExchangeItem.Quantity   = flowQuantity;
            _inputExchangeItems.Add(wholeRiverInputExchangeItem);

            // --- Populate output exchange items for flow in river branches ---
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                Element element = new Element();
                element.ID = "Branch:" + i.ToString();
                ElementSet elementSet = new ElementSet("Individual nodes", "Branch:" + i.ToString(), ElementType.IDBased, new SpatialReference("no reference"));
                elementSet.AddElement(element);
                OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
                outputExchangeItem.ElementSet = elementSet;
                outputExchangeItem.Quantity   = flowQuantity;

                _outputExchangeItems.Add(outputExchangeItem);
            }

            // --- polulate output exchange items for leakage for individual branches --
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                Element element = new Element();
                element.ID = "Branch:" + i.ToString();
                ElementSet elementSet = new ElementSet("Individual nodes", "Branch:" + i.ToString(), ElementType.IDBased, new SpatialReference("no reference"));
                elementSet.AddElement(element);
                OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
                outputExchangeItem.ElementSet = elementSet;
                outputExchangeItem.Quantity   = leakageQuantity;
                _outputExchangeItems.Add(outputExchangeItem);
            }

            // --- Populate output exchange item for leakage from the whole georeferenced river ---
            OutputExchangeItem wholeRiverOutputExchangeItem = new OutputExchangeItem();

            wholeRiverOutputExchangeItem.ElementSet = fullRiverElementSet;
            wholeRiverOutputExchangeItem.Quantity   = leakageQuantity;
            _outputExchangeItems.Add(wholeRiverOutputExchangeItem);

            // --- populate with initial state variables ---
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                _flow[i] = 7;
            }

            _currentTimeStepNumber      = 1;
            _initializeMethodWasInvoked = true;
        }
        public void Initialize(System.Collections.Hashtable properties)
        {
            getValuesWatch   = new Stopwatch();
            setValuesWatch   = new Stopwatch();
            performStepWatch = new Stopwatch();

            //List of exchange Items
            inputExchangeItems  = new List <InputExchangeItem>();
            outputExchangeItems = new List <OutputExchangeItem>();

            //Initializes Engine
            mohidLandEngine = new MohidLandEngineDotNetAccess();
            mohidLandEngine.Initialize(properties["FilePath"].ToString());


            //
            //Dimensions
            //
            Dimension dimFlow = new Dimension();

            dimFlow.SetPower(DimensionBase.Length, 3);
            dimFlow.SetPower(DimensionBase.Time, -1);

            Dimension dimWaterlevel = new Dimension();

            dimWaterlevel.SetPower(DimensionBase.Length, 1);

            Dimension dimWaterColumn = new Dimension();

            dimWaterColumn.SetPower(DimensionBase.Length, 1);

            Dimension dimConcentration = new Dimension();

            dimConcentration.SetPower(DimensionBase.Mass, 1);
            dimConcentration.SetPower(DimensionBase.Length, -3);

            //
            //Units
            //
            Unit unitFlow          = new Unit("m3/sec", 1, 0, "cubic meter per second");
            Unit unitWaterLevel    = new Unit("m", 1, 0, "meters above mean sea level");
            Unit unitWaterColumn   = new Unit("m", 1, 0, "meters above ground");
            Unit unitConcentration = new Unit("mg/l", 1, 0, "miligram per liter");

            //
            //Quantities
            //
            qtdOutflow     = new Quantity(unitFlow, "Flow discharge at the outlet", "Outlet Flow", ValueType.Scalar, dimFlow);
            qtdOutletLevel = new Quantity(unitWaterLevel, "Waterlevel at the outlet", "OutletLevel",
                                          ValueType.Scalar, dimWaterlevel);
            qtdWaterColumn = new Quantity(unitWaterColumn, "Ponded Water Column", "WaterColumn",
                                          ValueType.Scalar, dimWaterColumn);
            qtdDischarges = new Quantity(unitFlow, "Distributed discharges (sewer sinks)", "Discharges", ValueType.Scalar,
                                         dimFlow);

            qtdFlowToStorm = new Quantity(unitFlow, "Flow from the network to the storm water system (inlets)",
                                          "Storm Water Out Flow", ValueType.Scalar, dimFlow);

            qtdFlowFromStrom = new Quantity(unitFlow, "Flow from the storm water system to the network (discharges)",
                                            "Storm Water In Flow", ValueType.Scalar, dimFlow);

            //
            //Spatial Reference
            //
            SpatialReference spatialReference = new SpatialReference("spatial reference");

            //
            //Element Sets
            //

            //Model Grid
            ElementSet modelGrid = new ElementSet("Model Grid Points of all Compute Points", "Model Grid",
                                                  ElementType.XYPolygon, spatialReference);

            //Output exchange items - properties in each grid cell (surface only)
            numberOfWaterPoints = 0;
            for (int j = 1; j <= mohidLandEngine.GetJUB(horizontalGridInstanceID); j++)
            {
                for (int i = 1; i <= mohidLandEngine.GetIUB(horizontalGridInstanceID); i++)
                {
                    if (mohidLandEngine.IsWaterPoint(horizontalMapInstanceID, i, j))
                    {
                        String name = "i=" + i.ToString() + "/j=" + j.ToString();

                        double[] xCoords = new double[5];
                        double[] yCoords = new double[5];
                        mohidLandEngine.GetGridCellCoordinates(horizontalGridInstanceID, i, j, ref xCoords, ref yCoords);

                        Element element = new Element(name);
                        element.AddVertex(new Vertex(xCoords[0], yCoords[0], 0));
                        element.AddVertex(new Vertex(xCoords[1], yCoords[1], 0));
                        element.AddVertex(new Vertex(xCoords[2], yCoords[2], 0));
                        element.AddVertex(new Vertex(xCoords[3], yCoords[3], 0));

                        modelGrid.AddElement(element);

                        numberOfWaterPoints++;
                    }
                }
            }

            //Outlet Node
            ElementSet outletNode    = new ElementSet("Outlet node", "Outlet", ElementType.XYPoint, spatialReference);
            Element    outletElement = new Element("Outlet");
            int        outletNodeID  = mohidLandEngine.GetOutletNodeID(drainageNetworkInstanceID);

            outletElement.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, outletNodeID),
                                               mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, outletNodeID),
                                               0));
            outletNode.AddElement(outletElement);

            //Outflow to Storm Water Model
            ElementSet stormWaterOutflowNodes = new ElementSet("Nodes which provide flow to the Storm Water System",
                                                               "Storm Water Inlets", ElementType.XYPoint, spatialReference);
            int numberOfOutflowNodes = mohidLandEngine.GetNumberOfStormWaterOutFlowNodes(drainageNetworkInstanceID);

            int[] outflowNodeIDs = new int[numberOfOutflowNodes];
            mohidLandEngine.GetStormWaterOutflowIDs(drainageNetworkInstanceID, numberOfOutflowNodes, ref outflowNodeIDs);
            for (int i = 1; i <= numberOfOutflowNodes; i++)
            {
                int nodeID = outflowNodeIDs[i - 1];

                Element element = new Element(nodeID.ToString());
                element.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, nodeID),
                                             mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, nodeID),
                                             0));
                stormWaterOutflowNodes.AddElement(element);
            }

            //Inflow from Storm Water Model
            ElementSet stormWaterInflowNodes = new ElementSet("Nodes which receive flow to the Storm Water System",
                                                              "Storm Water Outlets", ElementType.XYPoint, spatialReference);
            int numberOfInflowNodes = mohidLandEngine.GetNumberOfStormWaterInFlowNodes(drainageNetworkInstanceID);

            if (numberOfInflowNodes > 0)
            {
                int[] inflowNodeIDs = new int[numberOfInflowNodes];
                mohidLandEngine.GetStormWaterInflowIDs(drainageNetworkInstanceID, numberOfOutflowNodes,
                                                       ref inflowNodeIDs);
                for (int i = 1; i <= numberOfInflowNodes; i++)
                {
                    int nodeID = inflowNodeIDs[i - 1];

                    Element element = new Element(nodeID.ToString());
                    element.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, nodeID),
                                                 mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, nodeID),
                                                 0));
                    stormWaterInflowNodes.AddElement(element);
                }
            }


            //
            //Output Exchange Items
            //

            //Flow at the outlet
            OutputExchangeItem outletFlow = new OutputExchangeItem();

            outletFlow.Quantity   = qtdOutflow;
            outletFlow.ElementSet = outletNode;
            outputExchangeItems.Add(outletFlow);

            //Overland water column
            OutputExchangeItem overlandWaterColumn = new OutputExchangeItem();

            overlandWaterColumn.Quantity   = qtdWaterColumn;
            overlandWaterColumn.ElementSet = modelGrid;
            outputExchangeItems.Add(overlandWaterColumn);

            //Flow to the Storm Water Model
            if (stormWaterOutflowNodes.ElementCount > 0)
            {
                OutputExchangeItem stormWaterOutFlow = new OutputExchangeItem();
                stormWaterOutFlow.Quantity   = qtdFlowToStorm;
                stormWaterOutFlow.ElementSet = stormWaterOutflowNodes;
                outputExchangeItems.Add(stormWaterOutFlow);
            }

            //
            //Input Exchange Items
            //

            //Water level at the outlet
            InputExchangeItem outletLevel = new InputExchangeItem();

            outletLevel.Quantity   = qtdOutletLevel;
            outletLevel.ElementSet = outletNode;
            inputExchangeItems.Add(outletLevel);

            //Distributed discharges
            InputExchangeItem dischargeInflow = new InputExchangeItem();

            dischargeInflow.Quantity   = qtdDischarges;
            dischargeInflow.ElementSet = modelGrid;
            inputExchangeItems.Add(dischargeInflow);

            //Flow from the Storm Water Model
            if (stormWaterInflowNodes.ElementCount > 0)
            {
                InputExchangeItem stormWaterInFlow = new InputExchangeItem();
                stormWaterInFlow.Quantity   = qtdFlowFromStrom;
                stormWaterInFlow.ElementSet = stormWaterInflowNodes;
                inputExchangeItems.Add(stormWaterInFlow);
            }

            //
            //Properties
            //

            //Properties input / output exchange items
            for (int i = 1; i <= mohidLandEngine.GetNumberOfProperties(drainageNetworkInstanceID); i++)
            {
                int    propertyIDNumber = mohidLandEngine.GetPropertyIDNumber(drainageNetworkInstanceID, i);
                string propertyName     = mohidLandEngine.GetPropertyNameByIDNumber(propertyIDNumber);

                Quantity concentrationQuantity = new Quantity(unitConcentration, "Concentration of " + propertyName,
                                                              propertyIDNumber.ToString(), ValueType.Scalar, dimConcentration);

                OutputExchangeItem outletConc = new OutputExchangeItem();
                outletConc.Quantity   = concentrationQuantity;
                outletConc.ElementSet = outletNode;

                outputExchangeItems.Add(outletConc);


                InputExchangeItem boundaryConc = new InputExchangeItem();
                boundaryConc.Quantity   = concentrationQuantity;
                boundaryConc.ElementSet = outletNode;

                inputExchangeItems.Add(boundaryConc);
            }
        }
        public override void Initialize(System.Collections.Hashtable properties)
        {
            string configFile = null; string U = null; string d = null; string C = null; string inputfile = null;

            //set initial conditions through *.omi file. (optional)
            if (properties.ContainsKey("ConfigFile"))
            {
                configFile = (string)properties["ConfigFile"];
            }

            if (properties.ContainsKey("Inputs"))
            {
                inputfile = (string)properties["Inputs"];
            }

            if (properties.ContainsKey("OutputDir"))
            {
                outputPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), (string)properties["OutputDir"]);
            }



            //lookup model's configuration file to determine interface properties
            SetVariablesFromConfigFile(configFile);
            SetValuesTableFields();


            int num_inputs = this.GetInputExchangeItemCount();

            if (inputfile != null)
            {
                //read input Ux,Uy,and concentration matrix
                StreamReader sr   = new StreamReader(inputfile);
                string       line = sr.ReadLine();
                u = Convert.ToDouble(line.Split(',')[1]);

                line = sr.ReadLine();
                D    = Convert.ToDouble(line.Split(',')[1]);

                line   = sr.ReadLine();
                rows_W = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                cols_W = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                rows_S = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                cols_S = Convert.ToInt32(line.Split(',')[1]);

                cw = new double[rows_W, cols_W]; cs = new double[rows_S, cols_S];

                //get input and output element sets from the SMW
                ElementSet ein  = (ElementSet)this.Inputs[0].ElementSet;
                ElementSet eout = (ElementSet)this.Outputs[0].ElementSet;

                //set some element set properties
                ein.ElementType  = OpenMI.Standard.ElementType.XYPoint;
                eout.ElementType = OpenMI.Standard.ElementType.XYPoint;

                //initialize cw to intial values (importating the data from the txt file(.models\water\inputs.csv))
                line = sr.ReadLine();
                int i = 0;
                while (line != null)
                {
                    string[] values = line.Split(',');

                    for (int j = 0; j <= values.Length - 1; j++)
                    {
                        cw[i, j] = Convert.ToDouble(values[j]);

                        //create element
                        Element e  = new Element();
                        Vertex  v1 = new Vertex(j, i, 0);
                        e.AddVertex(v1);

                        //add element to elementset
                        ein.AddElement(e);
                        eout.AddElement(e);
                    }

                    i++;
                    line = sr.ReadLine();
                }
            }
            else
            {
            }


            //output exchange item attributes
            int num_outputs           = this.GetOutputExchangeItemCount();
            OutputExchangeItem output = this.GetOutputExchangeItem(num_outputs - 1);

            output_elementset = output.ElementSet.ID;
            output_quantity   = output.Quantity.ID;

            //defining the equation constants
            _dt = this.GetTimeStep();
            _h  = u * _dt / 0.85533;

            //setup the intial value of adv_prev=cw since cw contain 1 row only
            adv_prev = cw;

            //this sets the initial cond.
            double[] outvals = new double[cw.GetLength(1)];
            for (int i = 0; i <= cw.GetLength(1) - 1; i++)
            {
                outvals[i] = cw[cw.GetLength(0) - 1, i];
            }
            this.SetValues("Concentration", "water", new ScalarSet(outvals));

            //setup initial value to be used once to bypass the first step due to openmi setting
            initial = new double[rows_W, cols_W];
            for (int i = 0; i <= cw.GetLength(0) - 1; i++)
            {
                for (int j = 0; j <= cw.GetLength(1) - 1; j++)
                {
                    initial[i, j] = cw[i, j];
                }
            }

            //calling the intial value of diff_prev=upper row of cs from sediment component
            diff_prev = new double[cs.GetUpperBound(1) + 1];
            for (int i = 0; i <= cs.GetLength(1) - 1; i++)
            {
                diff_prev[i] = cs[cs.GetUpperBound(0), i];
            }
        }
Beispiel #11
0
        private void CreateExchangeItemsFromXMLNode(XmlNode ExchangeItem, string Identifier, int eid)
        {
            //-- get dimension child nodes
            XmlNodeList children             = ExchangeItem.ChildNodes;
            XmlNode     quantityNode         = children[1]; //HACK
            Dictionary <string, double> dims = new Dictionary <string, double>();

            foreach (XmlNode child in quantityNode)
            {
                if (child.Name == "Dimensions")
                {
                    foreach (XmlNode dimension in child.ChildNodes)
                    {
                        //-- get the inner xml for the element
                        string text = dimension.InnerXml;

                        //-- get the start and end indices of "base" and "power"
                        int[] indices = new int[4] {
                            text.IndexOf("<Base>") + 6, text.IndexOf("</Base>") - 1,
                            text.IndexOf("<Power>") + 7, text.IndexOf("</Power>") - 1
                        };

                        //-- build base
                        string Base = "";
                        for (int i = indices[0]; i <= indices[1]; i++)
                        {
                            Base += text[i];
                        }

                        //-- build power
                        string power = "";
                        for (int i = indices[2]; i <= indices[3]; i++)
                        {
                            power += text[i];
                        }

                        //-- store dimension name and power
                        dims.Add(Base, Convert.ToDouble(power));
                    }
                }
            }


            //XmlNode dims = ExchangeItem.SelectSingleNode("//Dimensions");

            //Create Dimensions
            Dimension omiDimensions = new Dimension();

            //XmlNodeList dimensions = ExchangeItem.SelectNodes("//Dimensions/Dimension"); // You can filter elements here using XPath
            foreach (KeyValuePair <string, double> dim in dims)
            {
                if (dim.Key.ToUpper() == "LENGTH")
                {
                    omiDimensions.SetPower(DimensionBase.Length, dim.Value);
                }
                else if (dim.Key.ToUpper() == "TIME")
                {
                    omiDimensions.SetPower(DimensionBase.Time, dim.Value);
                }
                else if (dim.Key.ToUpper() == "AMOUNTOFSUBSTANCE")
                {
                    omiDimensions.SetPower(DimensionBase.AmountOfSubstance, dim.Value);
                }
                else if (dim.Key.ToUpper() == "CURRENCY")
                {
                    omiDimensions.SetPower(DimensionBase.Currency, dim.Value);
                }
                else if (dim.Key.ToUpper() == "ELECTRICCURRENT")
                {
                    omiDimensions.SetPower(DimensionBase.ElectricCurrent, dim.Value);
                }
                else if (dim.Key.ToUpper() == "LUMINOUSINTENSITY")
                {
                    omiDimensions.SetPower(DimensionBase.LuminousIntensity, dim.Value);
                }
                else if (dim.Key.ToUpper() == "MASS")
                {
                    omiDimensions.SetPower(DimensionBase.Mass, dim.Value);
                }
                else if (dim.Key.ToUpper() == "TEMPERATURE")
                {
                    omiDimensions.SetPower(DimensionBase.Temperature, dim.Value);
                }
            }

            //Create Units
            _omiUnits = new Unit();
            XmlNode units = ExchangeItem.SelectSingleNode("Quantity/Unit");

            _omiUnits.ID = units["ID"].InnerText;
            if (units["Description"] != null)
            {
                _omiUnits.Description = units["Description"].InnerText;
            }
            if (units["ConversionFactorToSI"] != null)
            {
                _omiUnits.ConversionFactorToSI = Convert.ToDouble(units["ConversionFactorToSI"].InnerText);
            }
            if (units["OffSetToSI"] != null)
            {
                _omiUnits.OffSetToSI = Convert.ToDouble(units["OffSetToSI"].InnerText);
            }

            //Create Quantity
            Quantity omiQuantity = new Quantity();
            XmlNode  quantity    = ExchangeItem.SelectSingleNode("Quantity");

            omiQuantity.ID = quantity["ID"].InnerText;
            if (quantity["Description"] != null)
            {
                omiQuantity.Description = quantity["Description"].InnerText;
            }
            omiQuantity.Dimension = omiDimensions;
            omiQuantity.Unit      = _omiUnits;
            if (quantity["ValueType"] != null)
            {
                if (quantity["ValueType"].InnerText == "Scalar")
                {
                    omiQuantity.ValueType = OpenMI.Standard.ValueType.Scalar;
                }
                else if (quantity["ValueType"].InnerText == "Vector")
                {
                    omiQuantity.ValueType = OpenMI.Standard.ValueType.Vector;
                }
            }

            //Create Element Set
            ElementSet omiElementSet = new ElementSet();
            XmlNode    elementSet    = ExchangeItem.SelectSingleNode("ElementSet");

            omiElementSet.ID = elementSet["ID"].InnerText;
            if (elementSet["Description"] != null)
            {
                omiElementSet.Description = elementSet["Description"].InnerText;
            }

            try
            {
                //add elements from shapefile to element set
                SMW.Utilities utils = new SMW.Utilities();
                _shapefilepath = elementSet["ShapefilePath"].InnerText;
                omiElementSet  = utils.AddElementsFromShapefile(omiElementSet, _shapefilepath);
            }
            catch (Exception)
            {
                Debug.WriteLine("An Element Set has not been declared using AddElementsFromShapefile");
            }



            if (Identifier == "OutputExchangeItem")
            {
                //create exchange item
                OutputExchangeItem omiOutputExchangeItem = new OutputExchangeItem();
                omiOutputExchangeItem.Quantity   = omiQuantity;
                omiOutputExchangeItem.ElementSet = omiElementSet;

                //add the output exchange item to the list of output exchange items for the component
                this._outputs.Add(omiOutputExchangeItem);
                if (!this._quantities.ContainsKey(omiQuantity.ID))
                {
                    this._quantities.Add(omiQuantity.ID, omiQuantity);
                }
                if (!this._elementSets.ContainsKey(omiElementSet.ID))
                {
                    this._elementSets.Add(omiElementSet.ID, omiElementSet);
                }
            }
            else if (Identifier == "InputExchangeItem")
            {
                //create exchange item
                InputExchangeItem omiInputExchangeItem = new InputExchangeItem();
                omiInputExchangeItem.Quantity   = omiQuantity;
                omiInputExchangeItem.ElementSet = omiElementSet;


                //add the output exchange item to the list of output exchange items for the component
                this._inputs.Add(omiInputExchangeItem);
                if (!this._quantities.ContainsKey(omiQuantity.ID))
                {
                    this._quantities.Add(omiQuantity.ID, omiQuantity);
                }
                if (!this._elementSets.ContainsKey(omiElementSet.ID))
                {
                    this._elementSets.Add(omiElementSet.ID, omiElementSet);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// This method is used to construct the component
        /// </summary>
        /// <param name="properties">arguments stored in the *.omi file</param>
        public void Initialize(IArgument[] properties)
        {
            //extract argument(s) from OMI file
            foreach (IArgument property in properties)
            {
                //overwrite the connection string, if one is given in the *.omi
                if (property.Key == "DbPath")
                {
                    _dbPath = property.Value;
                }

                //default value for relationFactor is 1;
                if (property.Key == "Relaxation")
                {
                    _smartBuffer.RelaxationFactor = Convert.ToDouble(property.Value);
                }
                if (property.Key == "IgnoreValue")
                {
                    _ignore = Convert.ToDouble(property.Value);
                }
            }

            //---- set database to default if dbpath is invalid
            string fullpath = "";
            //-- first check if dbpath is null
            bool pass = true;

            if (String.IsNullOrWhiteSpace(_dbPath))
            {
                pass = false;
            }
            //-- next, check that dbpath points to an actual file
            else
            {
                //-- if relative path is given
                if (!Path.IsPathRooted(_dbPath))
                {
                    fullpath = System.IO.Path.GetFullPath(System.IO.Directory.GetCurrentDirectory() + _dbPath);
                }
                //-- if absolute path
                else
                {
                    fullpath = System.IO.Path.GetFullPath(_dbPath);
                }

                if (!File.Exists(fullpath))
                {
                    pass = false;

                    //-- warn the user that the database could not be found
                    System.Windows.Forms.MessageBox.Show("The database supplied in DbWriter.omi could not be found. As a result the DbWriter will connect to the current HydroDesktop database." +
                                                         "\n\n--- The following database could not be found --- \n" + fullpath,
                                                         "An Error Occurred While Loading Database...",
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
            }


            //-- set the connection string
            if (!pass)
            {
                conn = Settings.Instance.DataRepositoryConnectionString;
            }
            else
            {
                //FileInfo fi = new FileInfo(fullpath);
                //conn = @"Data Source = " + fi.FullName + ";New=False;Compress=True;Version=3";
                conn = @"Data Source = " + fullpath + ";New=False;Compress=True;Version=3";
            }


            //---- read db info provided by omi
            dbargs = ReadDbArgs(properties);

            //---- create generic input and output exchange items
            InputExchangeItem inExchangeItem = new InputExchangeItem();

            inExchangeItem.ElementSet = new ElementSet("any element set", "any element set", ElementType.IDBased, new Oatc.OpenMI.Sdk.Backbone.SpatialReference("1"));
            inExchangeItem.Quantity   = new Quantity("any quantity");
            _inputExchangeItems.Add(inExchangeItem);

            OutputExchangeItem outExchangeItem = new OutputExchangeItem();

            outExchangeItem.ElementSet = new ElementSet("dummy element set", "dummy element set", ElementType.IDBased, new Oatc.OpenMI.Sdk.Backbone.SpatialReference("1"));
            outExchangeItem.Quantity   = new Quantity("dummy quantity");
            _outputExchangeItems.Add(outExchangeItem);

            //---- define arbitrary start and end times
            _earliestInputTime = CalendarConverter.Gregorian2ModifiedJulian(new DateTime(1900, 1, 1));
            _latestInputTime   = CalendarConverter.Gregorian2ModifiedJulian(new DateTime(2100, 12, 31));
        }
Beispiel #13
0
        public override void Initialize(System.Collections.Hashtable properties)
        {
            string configFile = null;
            string data_dir = null;

            //Get Config file directory from .omi file
            if (properties.ContainsKey("ConfigFile"))
                configFile = (string)properties["ConfigFile"];
            //Get wtmp files directory from .omi file
            if (properties.ContainsKey("DataFolder"))
                data_dir = (string)properties["DataFolder"];

            //Set variables
            SetVariablesFromConfigFile(configFile);
            SetValuesTableFields();

            //get output exchange item attributes
            int num_outputs = this.GetOutputExchangeItemCount();
            OutputExchangeItem output_1 = this.GetOutputExchangeItem(num_outputs - 12);
            output_elementset_1 = output_1.ElementSet.ID;
            output_quantity_1 = output_1.Quantity.ID;
            OutputExchangeItem output_2 = this.GetOutputExchangeItem(num_outputs - 11);
            output_elementset_2 = output_2.ElementSet.ID;
            output_quantity_2 = output_2.Quantity.ID;
            OutputExchangeItem output = this.GetOutputExchangeItem(num_outputs - 10);
            output_elementset0 = output.ElementSet.ID;
            output_quantity0 = output.Quantity.ID;
            OutputExchangeItem output1 = this.GetOutputExchangeItem(num_outputs - 9);
            output_elementset1 = output1.ElementSet.ID;
            output_quantity1 = output1.Quantity.ID;
            OutputExchangeItem output2 = this.GetOutputExchangeItem(num_outputs - 8);
            output_elementset2 = output2.ElementSet.ID;
            output_quantity2 = output2.Quantity.ID;
            OutputExchangeItem output3 = this.GetOutputExchangeItem(num_outputs - 7);
            output_elementset3 = output3.ElementSet.ID;
            output_quantity3 = output3.Quantity.ID;
            OutputExchangeItem output4 = this.GetOutputExchangeItem(num_outputs - 6);
            output_elementset4 = output4.ElementSet.ID;
            output_quantity4 = output4.Quantity.ID;
            OutputExchangeItem output5 = this.GetOutputExchangeItem(num_outputs - 5);
            output_elementset5 = output5.ElementSet.ID;
            output_quantity5 = output5.Quantity.ID;
            OutputExchangeItem output6 = this.GetOutputExchangeItem(num_outputs - 4);
            output_elementset6 = output6.ElementSet.ID;
            output_quantity6 = output6.Quantity.ID;
            OutputExchangeItem output7 = this.GetOutputExchangeItem(num_outputs - 3);
            output_elementset7 = output7.ElementSet.ID;
            output_quantity7 = output7.Quantity.ID;
            OutputExchangeItem output8 = this.GetOutputExchangeItem(num_outputs - 2);
            output_elementset8 = output8.ElementSet.ID;
            output_quantity8 = output8.Quantity.ID;
            OutputExchangeItem output9 = this.GetOutputExchangeItem(num_outputs - 1);
            output_elementset9 = output9.ElementSet.ID;
            output_quantity9 = output9.Quantity.ID;

            ////////////specifiying shp file/////////////
            //Get the input and output element sets from the SMW
            ElementSet out_elem = (ElementSet)this.Outputs[0].ElementSet;
            //Set some ElementSet properties
            out_elem.ElementType = OpenMI.Standard.ElementType.XYPoint;



            //Get all the values from .wtmp file
            string[] wtmDir = Directory.GetFiles(data_dir, "*wtmp");
            string line;
            for (int f = 0; f < wtmDir.Length; f++)
            {
                //defining average arrays for whole data[0] and months[1],[2]....[12]
                double[] AvTemp = new double[13];
                double[] AvDew = new double[13];
                double[] AvTmax = new double[13];
                double[] AvTmin = new double[13];
                double[] AvWnd = new double[13];

                List<double[]> wtmp = new List<double[]>();
                StreamReader data = new StreamReader(wtmDir[f]);
                line = data.ReadLine(); //Read first info line...
                line = data.ReadLine(); //Read Second line...
                double[] StationInfo = new double[4];
                StationInfo[0] = Convert.ToDouble(line.Split(',')[11]); //Read StationID from second line
                StationInfo[1] = Convert.ToDouble(line.Split(',')[3]); //Read Latitude from second line
                StationInfo[2] = Convert.ToDouble(line.Split(',')[5]); //Read Longitude from second line
                StationInfo[3] = Convert.ToDouble((line.Split(',')[1]).Substring(0, (line.Split(',')[1]).Length - 1));//(line.Split(',')[1]);for the tab at the end of elevation //Read Elevation from second line

                ////////////specifiying shp file (continues)/////////////
                //Create elements 
                Element e1 = new Element();
                Vertex v1 = new Vertex(StationInfo[2], StationInfo[1], StationInfo[3]);
                e1.AddVertex(v1);
                out_elem.AddElement(e1);

                
                line = data.ReadLine(); //Read Third info line...
                while ((line = data.ReadLine()) != null)
                {
                    string[] column = line.Split(',');
                    double[] values = new double[10];
                    values[0] = Convert.ToDouble(column[0]); //date
                    values[1] = Convert.ToDouble(column[1]); //Temperature
                    values[2] = Convert.ToDouble(column[2]); //Dew Point Temperature
                    values[3] = Convert.ToDouble(column[3]); //Maximum Temperature
                    values[4] = Convert.ToDouble(column[4]); //Minumum Temperature
                    values[5] = Convert.ToDouble(column[5]); //Wind Speed
                    wtmp.Add(values);
                }


                #region Getting avarage values for missing ones and replacing them


                //Get whole average values
                double SumTemp = 0; double st = 0; double SumDew = 0; double sd = 0; double SumTmax = 0;
                double stmx = 0; double SumTmin = 0; double stmn = 0; double SumWnd = 0; double sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                    if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                    if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                    if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                    if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                }
                AvTemp[0] = SumTemp / st;
                AvDew[0] = SumDew / sd;
                AvTmax[0] = SumTmax / stmx;
                AvTmin[0] = SumTmin / stmn;
                AvWnd[0] = SumWnd / sw;

                //Check if enough data is available for the gage
                if (st < 350 || sd < 350 || stmx < 350 || stmn < 350 || sw < 350)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }

                //Get Monthly average values
                //January
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "01")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[1] = SumTemp / st; } else { AvTemp[1] = AvTemp[0]; }
                if (sd != 0) { AvDew[1] = SumDew / sd; } else { AvDew[1] = AvDew[0]; }
                if (stmx != 0) { AvTmax[1] = SumTmax / stmx; } else { AvTmax[1] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[1] = SumTmin / stmn; } else { AvTmin[1] = AvTmin[0]; }
                if (sw != 0) { AvWnd[1] = SumWnd / sw; } else { AvWnd[1] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "01")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[1]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[1]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[1]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[1]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[1]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }

                //February
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "02")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[2] = SumTemp / st; } else { AvTemp[2] = AvTemp[0]; }
                if (sd != 0) { AvDew[2] = SumDew / sd; } else { AvDew[2] = AvDew[0]; }
                if (stmx != 0) { AvTmax[2] = SumTmax / stmx; } else { AvTmax[2] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[2] = SumTmin / stmn; } else { AvTmin[2] = AvTmin[0]; }
                if (sw != 0) { AvWnd[2] = SumWnd / sw; } else { AvWnd[2] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "02")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[2]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[2]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[2]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[2]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[2]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //March
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "03")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[3] = SumTemp / st; } else { AvTemp[3] = AvTemp[0]; }
                if (sd != 0) { AvDew[3] = SumDew / sd; } else { AvDew[3] = AvDew[0]; }
                if (stmx != 0) { AvTmax[3] = SumTmax / stmx; } else { AvTmax[3] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[3] = SumTmin / stmn; } else { AvTmin[3] = AvTmin[0]; }
                if (sw != 0) { AvWnd[3] = SumWnd / sw; } else { AvWnd[3] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "03")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[3]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[3]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[3]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[3]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[3]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //April
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "04")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[4] = SumTemp / st; } else { AvTemp[4] = AvTemp[0]; }
                if (sd != 0) { AvDew[4] = SumDew / sd; } else { AvDew[4] = AvDew[0]; }
                if (stmx != 0) { AvTmax[4] = SumTmax / stmx; } else { AvTmax[4] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[4] = SumTmin / stmn; } else { AvTmin[4] = AvTmin[0]; }
                if (sw != 0) { AvWnd[4] = SumWnd / sw; } else { AvWnd[4] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "04")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[4]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[4]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[4]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[4]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[4]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //May
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "05")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[5] = SumTemp / st; } else { AvTemp[5] = AvTemp[0]; }
                if (sd != 0) { AvDew[5] = SumDew / sd; } else { AvDew[5] = AvDew[0]; }
                if (stmx != 0) { AvTmax[5] = SumTmax / stmx; } else { AvTmax[5] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[5] = SumTmin / stmn; } else { AvTmin[5] = AvTmin[0]; }
                if (sw != 0) { AvWnd[5] = SumWnd / sw; } else { AvWnd[5] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "05")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[5]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[5]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[5]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[5]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[5]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //Jun
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "06")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[6] = SumTemp / st; } else { AvTemp[6] = AvTemp[0]; }
                if (sd != 0) { AvDew[6] = SumDew / sd; } else { AvDew[6] = AvDew[0]; }
                if (stmx != 0) { AvTmax[6] = SumTmax / stmx; } else { AvTmax[6] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[6] = SumTmin / stmn; } else { AvTmin[6] = AvTmin[0]; }
                if (sw != 0) { AvWnd[6] = SumWnd / sw; } else { AvWnd[6] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "06")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[6]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[6]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[6]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[6]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[6]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //July
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "07")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[7] = SumTemp / st; } else { AvTemp[7] = AvTemp[0]; }
                if (sd != 0) { AvDew[7] = SumDew / sd; } else { AvDew[7] = AvDew[0]; }
                if (stmx != 0) { AvTmax[7] = SumTmax / stmx; } else { AvTmax[7] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[7] = SumTmin / stmn; } else { AvTmin[7] = AvTmin[0]; }
                if (sw != 0) { AvWnd[7] = SumWnd / sw; } else { AvWnd[7] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "07")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[7]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[7]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[7]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[7]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[7]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //Agust
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "08")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[8] = SumTemp / st; } else { AvTemp[8] = AvTemp[0]; }
                if (sd != 0) { AvDew[8] = SumDew / sd; } else { AvDew[8] = AvDew[0]; }
                if (stmx != 0) { AvTmax[8] = SumTmax / stmx; } else { AvTmax[8] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[8] = SumTmin / stmn; } else { AvTmin[8] = AvTmin[0]; }
                if (sw != 0) { AvWnd[8] = SumWnd / sw; } else { AvWnd[8] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "08")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[8]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[8]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[8]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[8]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[8]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //September
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "09")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[9] = SumTemp / st; } else { AvTemp[9] = AvTemp[0]; }
                if (sd != 0) { AvDew[9] = SumDew / sd; } else { AvDew[9] = AvDew[0]; }
                if (stmx != 0) { AvTmax[9] = SumTmax / stmx; } else { AvTmax[9] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[9] = SumTmin / stmn; } else { AvTmin[9] = AvTmin[0]; }
                if (sw != 0) { AvWnd[9] = SumWnd / sw; } else { AvWnd[9] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "09")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[9]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[9]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[9]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[9]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[9]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //Octember
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "10")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[10] = SumTemp / st; } else { AvTemp[10] = AvTemp[0]; }
                if (sd != 0) { AvDew[10] = SumDew / sd; } else { AvDew[10] = AvDew[0]; }
                if (stmx != 0) { AvTmax[10] = SumTmax / stmx; } else { AvTmax[10] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[10] = SumTmin / stmn; } else { AvTmin[10] = AvTmin[0]; }
                if (sw != 0) { AvWnd[10] = SumWnd / sw; } else { AvWnd[10] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "10")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[10]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[10]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[10]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[10]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[10]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //November
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "11")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[11] = SumTemp / st; } else { AvTemp[11] = AvTemp[0]; }
                if (sd != 0) { AvDew[11] = SumDew / sd; } else { AvDew[11] = AvDew[0]; }
                if (stmx != 0) { AvTmax[11] = SumTmax / stmx; } else { AvTmax[11] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[11] = SumTmin / stmn; } else { AvTmin[11] = AvTmin[0]; }
                if (sw != 0) { AvWnd[11] = SumWnd / sw; } else { AvWnd[11] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "11")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[11]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[11]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[11]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[11]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[11]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                //December
                SumTemp = 0; st = 0; SumDew = 0; sd = 0; SumTmax = 0;
                stmx = 0; SumTmin = 0; stmn = 0; SumWnd = 0; sw = 0;
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "12")
                    {
                        if (wtmp[i][1] != -999.0) { SumTemp = SumTemp + (wtmp[i][1]); st++; }
                        if (wtmp[i][2] != -999.0) { SumDew = SumDew + (wtmp[i][2]); sd++; }
                        if (wtmp[i][3] != -999.0) { SumTmax = SumTmax + (wtmp[i][3]); stmx++; }
                        if (wtmp[i][4] != -999.0) { SumTmin = SumTmin + (wtmp[i][4]); stmn++; }
                        if (wtmp[i][5] != -999.0) { SumWnd = SumWnd + (wtmp[i][5]); sw++; }
                    }
                }
                if (st != 0) { AvTemp[12] = SumTemp / st; } else { AvTemp[12] = AvTemp[0]; }
                if (sd != 0) { AvDew[12] = SumDew / sd; } else { AvDew[12] = AvDew[0]; }
                if (stmx != 0) { AvTmax[12] = SumTmax / stmx; } else { AvTmax[12] = AvTmax[0]; }
                if (stmn != 0) { AvTmin[12] = SumTmin / stmn; } else { AvTmin[12] = AvTmin[0]; }
                if (sw != 0) { AvWnd[12] = SumWnd / sw; } else { AvWnd[12] = AvWnd[0]; }

                //Replacing Average values for the missing ones
                for (int i = 0; i < wtmp.Count; i++)//Count gives number of rows 
                {
                    if (Convert.ToString(wtmp[i][0]).Substring(4, 2) == "12")
                    {
                        if (wtmp[i][1] == -999.0) { wtmp[i][1] = AvTemp[12]; }
                        if (wtmp[i][2] == -999.0) { wtmp[i][2] = AvDew[12]; }
                        if (wtmp[i][3] == -999.0) { wtmp[i][3] = AvTmax[12]; }
                        if (wtmp[i][4] == -999.0) { wtmp[i][4] = AvTmin[12]; }
                        if (wtmp[i][5] == -999.0) { wtmp[i][5] = AvWnd[12]; }
                    }
                }
                //Check if enough data is available for the gage
                if (st < 25 || sd < 25 || stmx < 25 || stmn < 25 || sw < 25)
                {
                    StationInfo[0] = -999.0;//station id
                    StationInfo[1] = -999.0;//latitude
                    StationInfo[2] = -999.0;//longitude
                    StationInfo[3] = -999.0;//elevation
                }


                #endregion
                wtmp.Add(AvTmin); //The last forth is averagerage Min Temperature (Allwtmp[f][(Allwtmp[f].Count() - 4)][0, 1, ....,12])
                wtmp.Add(AvTmax); //The last thirth is averagerage Max Temperature (Allwtmp[f][(Allwtmp[f].Count() - 3)][0, 1, ....,12])
                wtmp.Add(StationInfo); //The one before last one is Station information (Allwtmp[f][(Allwtmp[f].Count() - 2)][0, 1, ....,3])
                wtmp.Add(AvTemp); //The last one is averagerage Temperature (Allwtmp[f][(Allwtmp[f].Count() - 1)][0, 1, ....,12])
                Allwtmp.Add(wtmp);
            }


            ////////////specifiying shp file (continues)/////////////
            //Giving shp file properties to other output exchange items.
            ElementSet TempMinNext = (ElementSet)this.Outputs[0].ElementSet;
            TempMinNext.ElementType = ElementType.XYPoint;
            TempMinNext.Elements = out_elem.Elements;
            ElementSet MonAvTemp = (ElementSet)this.Outputs[1].ElementSet;
            MonAvTemp.ElementType = ElementType.XYPoint;
            MonAvTemp.Elements = out_elem.Elements;
            ElementSet stID = (ElementSet)this.Outputs[2].ElementSet;
            stID.ElementType = ElementType.XYPoint;
            stID.Elements = out_elem.Elements;
            ElementSet lat = (ElementSet)this.Outputs[3].ElementSet;
            lat.ElementType = ElementType.XYPoint;
            lat.Elements = out_elem.Elements;
            ElementSet lon = (ElementSet)this.Outputs[4].ElementSet;
            lon.ElementType = ElementType.XYPoint;
            lon.Elements = out_elem.Elements;
            ElementSet elev = (ElementSet)this.Outputs[5].ElementSet;
            elev.ElementType = ElementType.XYPoint;
            elev.Elements = out_elem.Elements;
            ElementSet temp = (ElementSet)this.Outputs[6].ElementSet;
            temp.ElementType = ElementType.XYPoint;
            temp.Elements = out_elem.Elements;
            ElementSet tempd = (ElementSet)this.Outputs[7].ElementSet;
            tempd.ElementType = ElementType.XYPoint;
            tempd.Elements = out_elem.Elements;
            ElementSet tempmx = (ElementSet)this.Outputs[8].ElementSet;
            tempmx.ElementType = ElementType.XYPoint;
            tempmx.Elements = out_elem.Elements; 
            ElementSet tempmn = (ElementSet)this.Outputs[9].ElementSet;
            tempmn.ElementType = ElementType.XYPoint;
            tempmn.Elements = out_elem.Elements; 
            ElementSet winds = (ElementSet)this.Outputs[10].ElementSet;
            winds.ElementType = ElementType.XYPoint;
            winds.Elements = out_elem.Elements; 
            ElementSet date1 = (ElementSet)this.Outputs[11].ElementSet;
            date1.ElementType = ElementType.XYPoint;
            date1.Elements = out_elem.Elements;


        }
Beispiel #14
0
        public void Initialize(Hashtable properties) //part of System.Collections
        {
            _inputExchangeItems  = new ArrayList();
            _outputExchangeItems = new ArrayList();
            _elementSets         = new Hashtable();
            _elementScopes       = new Hashtable();
            FilePath             = ((string)properties["FilePath"]);

            InitializeDaisy((string)properties["FilePath"]);
            ModelDescription = ((string)GetDescription());

            for (int i = 0; i < _daisyEngine.ScopeSize(); i++)
            {
                Scope scope = _daisyEngine.GetScope(i);

                // Attribut column?
                if (!scope.HasString("column"))
                {
                    continue;
                }

                // Create element.
                string  columnID = scope.String("column");
                Element element  = new Element(columnID);
                _elementScopes[element] = scope;
                if (_daisyEngine.HasColumn(columnID))
                {
                    Column column = _daisyEngine.GetColumn(columnID);
                    for (uint ii = 0; ii < column.LocationSize(); ii++)
                    {
                        double x = column.LocationX(ii);
                        double y = column.LocationY(ii);
                        double z = 0.0;
                        element.AddVertex(new Vertex(x, y, z));
                    }
                }

                // Add exchange items.
                for (uint j = 0; j < scope.NumberSize(); j++)
                {
                    string     name = scope.NumberName(j);
                    ElementSet elementSet;

                    // Find or create element set.
                    if (_elementSets.Contains(name))
                    {
                        elementSet              = (ElementSet)_elementSets[name];
                        elementSet.Description += " " + columnID;
                        // TODO: We should test the type matches here.
                    }
                    else
                    {
                        switch (element.VertexCount)
                        {
                        case 0:
                            // ID based
                            elementSet = new ElementSet(columnID, name, ElementType.XYPoint, new SpatialReference(""));
                            break;

                        case 1:
                            // Point based
                            elementSet = new ElementSet(columnID, name, ElementType.XYPoint, new SpatialReference(""));
                            break;

                        case 2:
                            // Error
                            throw new ApplicationException("Error: Column must not contain exactly two (X Y)-points!");

                        default:
                            // Polygon
                            elementSet = new ElementSet(columnID, name, ElementType.XYPolygon, new SpatialReference(""));
                            break;
                        }
                        _elementSets[name] = elementSet;
                        string dim         = scope.Dimension(name);
                        string description = scope.Description(name);

                        Quantity quantity = Quantity(dim, description, name);
                        if (scope.Writeable())
                        {
                            InputExchangeItem input = new InputExchangeItem();
                            input.Quantity   = quantity;
                            input.ElementSet = elementSet;
                            _inputExchangeItems.Add(input);
                        }
                        else
                        {
                            OutputExchangeItem output = new OutputExchangeItem();
                            output.Quantity   = quantity;
                            output.ElementSet = elementSet;
                            _outputExchangeItems.Add(output);
                        }
                    }

                    // Add it.
                    elementSet.AddElement(element);
                }
            }
        }
        public override void Initialize(System.Collections.Hashtable properties)
        {
            //string configFile = null; string output_elementset; string output_quantity;
            string configFile = null; string inputfile = null;

            //set initial conditions through *.omi file. (optional)
            if (properties.ContainsKey("ConfigFile"))
            {
                configFile = (string)properties["ConfigFile"];
            }

            if (properties.ContainsKey("Inputs"))
            {
                inputfile = (string)properties["Inputs"];
            }


            if (properties.ContainsKey("OutputDir"))
            {
                outputPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), (string)properties["OutputDir"]);
            }


            //lookup model's configuration file to determine interface properties
            SetVariablesFromConfigFile(configFile);
            SetValuesTableFields();

            int num_inputs = this.GetInputExchangeItemCount();

            if (inputfile != null)
            {
                //read input Ux,Uy,and concentration matrix
                StreamReader sr   = new StreamReader(inputfile);
                string       line = sr.ReadLine();
                u = Convert.ToDouble(line.Split(',')[1]);

                line = sr.ReadLine();
                D    = Convert.ToDouble(line.Split(',')[1]);

                line   = sr.ReadLine();
                rows_S = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                cols_S = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                rows_W = Convert.ToInt32(line.Split(',')[1]);

                line   = sr.ReadLine();
                cols_W = Convert.ToInt32(line.Split(',')[1]);

                cs = new double[rows_S, cols_S]; cw = new double[rows_W, cols_W];

                //get elementset from smw
                ElementSet ein  = (ElementSet)this.Inputs[0].ElementSet;
                ElementSet eout = (ElementSet)this.Outputs[0].ElementSet;

                //change element type from id to point
                ein.ElementType  = ElementType.XYPoint;
                eout.ElementType = ElementType.XYPoint;

                //initialize cw to intial values (importating the data from the txt file(.models\sediment\inputs.csv)
                line = sr.ReadLine();
                int i = 0;
                while (line != null)
                {
                    string[] values = line.Split(',');
                    for (int j = 0; j <= values.Length - 1; j++)
                    {
                        cs[i, j] = Convert.ToDouble(values[j]);

                        //Build Element Set from first row only!
                        if (i == 0)
                        {
                            //create new element
                            Element e = new Element();
                            int     x, y;
                            x = j;
                            y = -i;
                            Vertex v = new Vertex(x, y, 0);
                            e.AddVertex(v);

                            //add element to elementset
                            ein.AddElement(e);
                            eout.AddElement(e);
                        }
                    }
                    i++;
                    line = sr.ReadLine();
                }
            }
            else
            {
            }


            //output exchange item attributes
            int num_outputs           = this.GetOutputExchangeItemCount();
            OutputExchangeItem output = this.GetOutputExchangeItem(num_outputs - 1);

            output_elementset = output.ElementSet.ID;
            output_quantity   = output.Quantity.ID;

            //defining the equation constants
            _dt = this.GetTimeStep();
            _h  = u * _dt / 0.85533;   // l / (rows - 2);

            //setup the intial value of diff_prev= upper row of cs since cs contain 9 rows
            diff_prev = new double[cs.GetUpperBound(1) + 1];
            for (int i = 0; i <= cs.GetLength(1) - 1; i++)
            {
                diff_prev[i] = cs[cs.GetUpperBound(0), i];
            }
            //this sets the initial cond.

            this.SetValues("Concentration", "sed", new ScalarSet(diff_prev));

            // intiating am matrix that contain the intial values to bypass the open mi setting
            initial = new double[cs.GetUpperBound(1) + 1];
            for (int i = 0; i <= cs.GetLength(1) - 1; i++)
            {
                initial[i] = cs[cs.GetUpperBound(0), i];
            }

            //calling the intial value of adv_prev=cw from water component
            adv_prev = new double[1, cw.GetUpperBound(1) + 1];
            for (int j = 0; j <= cw.GetLength(1) - 1; j++)
            {
                adv_prev[0, j] = cw[cw.GetUpperBound(0), j];
            }
        }