public IEnumerator <ParameterValueElement2Dimensional <T> > GetEnumerator() { for (int i = 0; i < Length0; i++) { for (int l = 0; l < Length1; l++) { var key = new ParameterElementKey2Dimensional(Id, this.Name, i, l); yield return(new ParameterValueElement2Dimensional <T>(key, Name, Id, i, l, _values[i, l])); } } }
public override IEnumerable <ParameterValueElementNonTyped> GetAllElements() { for (int i = 0; i < Length0; i++) { for (int l = 0; l < Length1; l++) { var key = new ParameterElementKey2Dimensional(Id, this.Name, i, l); yield return(new ParameterValueElement2Dimensional <T>(key, Name, Id, i, l, _values[i, l])); } } }
public override bool Equals(object obj) { if (obj == null) { return(false); } ParameterElementKey2Dimensional p = obj as ParameterElementKey2Dimensional; if (p == null) { return(false); } return(_id == p._id && _dim1 == p._dim1 && _dim2 == p._dim2); }
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(); } } ; } ; }
ParameterValueElementNonTyped IParameterValue2DimensionalTypeless.GetElement(int index1, int index2) { var key = new ParameterElementKey2Dimensional(Id, this.Name, index1, index2); return(new ParameterValueElement2Dimensional <T>(key, Name, Id, index1, index2, _values[index1, index2])); }