示例#1
0
 public IEnumerator <ParameterValueElement1Dimensional <T> > GetEnumerator()
 {
     for (int i = 0; i < _values.Length; i++)
     {
         var key = new ParameterElementKey1Dimensional(Id, this.Name, i);
         yield return(new ParameterValueElement1Dimensional <T>(key, Name, Id, i, _values[i]));
     }
 }
示例#2
0
 public override IEnumerable <ParameterValueElementNonTyped> GetAllElements()
 {
     for (int i = 0; i < _values.Length; i++)
     {
         var key = new ParameterElementKey1Dimensional(Id, this.Name, i);
         yield return(new ParameterValueElement1Dimensional <T>(key, Name, Id, i, _values[i]));
     }
 }
示例#3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ParameterElementKey1Dimensional p = obj as ParameterElementKey1Dimensional;

            if (p == null)
            {
                return(false);
            }

            return(_id == p._id && _dim1 == p._dim1);
        }
示例#4
0
        ParameterValueElementNonTyped IParameterValue1DimensionalTypeless.GetElement(int index)
        {
            var key = new ParameterElementKey1Dimensional(Id, this.Name, index);

            return(new ParameterValueElement1Dimensional <T>(key, Name, Id, index, _values[index]));
        }
        private void ReadExcel2007File(string filename)
        {
            var excelParameters = new Esmf.FundExcelParameterFile(filename);

            excelParameters.Load();

            foreach (Esmf.FundExcelParameterFile.Parameter p in excelParameters.Parameters)
            {
                string parameterName = p.Name.ToLower();
                int    parameterId   = -1;

                if (!_parameterIdsByName.TryGetValue(parameterName, out parameterId))
                {
                    parameterId = _nextFreeId;
                    _parameterIdsByName.Add(parameterName, parameterId);
                    _nextFreeId++;
                }

                if (p is Esmf.FundExcelParameterFile.NonDimensionalParameter)
                {
                    var typedExcelParameter = (Esmf.FundExcelParameterFile.NonDimensionalParameter)p;

                    var key = new ParameterElementKey(parameterId, parameterName);

                    var parameterValueDef = GetParameterValueDefinition(key, p.Type, typedExcelParameter.Value);

                    if (parameterValueDef.GetElementType() == typeof(double))
                    {
                        var parameter = new ParameterNonDimensional <double>(parameterName, parameterId, (ParameterElement <double>)parameterValueDef);

                        Add(parameter);
                    }
                    else if (parameterValueDef.GetElementType() == typeof(Timestep))
                    {
                        var parameter = new ParameterNonDimensional <Timestep>(parameterName, parameterId, (ParameterElement <Timestep>)parameterValueDef);

                        Add(parameter);
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                else if (p is Esmf.FundExcelParameterFile.OneDimensionalParameter)
                {
                    var pp = (Esmf.FundExcelParameterFile.OneDimensionalParameter)p;

                    var parameterValueDef0 = GetParameterValueDefinition(null, p.Type, pp[0]);

                    if (parameterValueDef0.GetElementType() == typeof(double))
                    {
                        ParameterElement <double>[] values = new ParameterElement <double> [pp.Length];

                        for (int i = 0; i < pp.Length; i++)
                        {
                            var key = new ParameterElementKey1Dimensional(parameterId, parameterName, i);
                            values[i] = (ParameterElement <double>)GetParameterValueDefinition(key, p.Type, pp[i]);
                        }
                        var parameter = new ParameterOneDimensional <double>(parameterName, parameterId, values);

                        Add(parameter);
                    }
                    else if (parameterValueDef0.GetElementType() == typeof(Timestep))
                    {
                        ParameterElement <Timestep>[] values = new ParameterElement <Timestep> [pp.Length];

                        for (int i = 0; i < pp.Length; i++)
                        {
                            var key = new ParameterElementKey1Dimensional(parameterId, parameterName, i);
                            values[i] = (ParameterElement <Timestep>)GetParameterValueDefinition(key, p.Type, pp[i]);
                        }
                        var parameter = new ParameterOneDimensional <Timestep>(parameterName, parameterId, values);

                        Add(parameter);
                    }
                    else if (parameterValueDef0.GetElementType() == typeof(string))
                    {
                        ParameterElement <string>[] values = new ParameterElement <string> [pp.Length];

                        for (int i = 0; i < pp.Length; i++)
                        {
                            var key = new ParameterElementKey1Dimensional(parameterId, parameterName, i);
                            values[i] = (ParameterElement <string>)GetParameterValueDefinition(key, p.Type, pp[i]);
                        }
                        var parameter = new ParameterOneDimensional <string>(parameterName, parameterId, values);

                        Add(parameter);
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                else if (p is Esmf.FundExcelParameterFile.TwoDimensionalParameter)
                {
                    var pp = (Esmf.FundExcelParameterFile.TwoDimensionalParameter)p;

                    var parameterValueDef0 = GetParameterValueDefinition(null, p.Type, pp[0, 0]);

                    if (parameterValueDef0.GetElementType() == typeof(double))
                    {
                        ParameterElement <double>[,] values = new ParameterElement <double> [pp.Count0, pp.Count1];

                        for (int i = 0; i < pp.Count0; i++)
                        {
                            for (int l = 0; l < pp.Count1; l++)
                            {
                                var key = new ParameterElementKey2Dimensional(parameterId, parameterName, i, l);
                                values[i, l] = (ParameterElement <double>)GetParameterValueDefinition(key, p.Type, pp[i, l]);
                            }
                        }

                        var parameter = new Parameter2Dimensional <double>(parameterName, parameterId, values);

                        Add(parameter);
                    }
                    else if (parameterValueDef0.GetElementType() == typeof(Timestep))
                    {
                        ParameterElement <Timestep>[,] values = new ParameterElement <Timestep> [pp.Count0, pp.Count1];

                        for (int i = 0; i < pp.Count0; i++)
                        {
                            for (int l = 0; l < pp.Count1; l++)
                            {
                                var key = new ParameterElementKey2Dimensional(parameterId, parameterName, i, l);
                                values[i, l] = (ParameterElement <Timestep>)GetParameterValueDefinition(key, p.Type, pp[i, l]);
                            }
                        }

                        var parameter = new Parameter2Dimensional <Timestep>(parameterName, parameterId, values);

                        Add(parameter);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                ;
            }
            ;
        }