Beispiel #1
0
        private void AddDataVariable(TreatmentZone treatmentZone, NumericRepresentationValue value, string productId, IsoUnit unit)
        {
            if (value != null && value.Value != null)
            {
                var targetValue = value.Value.Value;

                // Convert input value to Iso unit
                var           adaptUnit = unit.ToAdaptUnit();
                UnitOfMeasure userUnit  = null;
                if (adaptUnit != null && value.Value.UnitOfMeasure != null &&
                    adaptUnit.Dimension == value.Value.UnitOfMeasure.Dimension)
                {
                    userUnit    = value.Value.UnitOfMeasure;
                    targetValue = _unitConverter.Convert(userUnit.ToInternalUom(), adaptUnit.ToInternalUom(), targetValue);
                }

                var dataVariable = new DataVariable
                {
                    ProductId = productId,
                    Value     = targetValue,
                    IsoUnit   = unit,
                    UserUnit  = userUnit
                };

                treatmentZone.Variables.Add(dataVariable);
            }
        }
Beispiel #2
0
        private string WriteGridFile(RasterGridPrescription prescription, TreatmentZone treatmentZone)
        {
            var gridFileName = GenerateId(5);

            using (var binaryWriter = CreateWriter(Path.ChangeExtension(gridFileName, ".BIN")))
            {
                byte[] previousBytes = BitConverter.GetBytes(0);
                foreach (var rxRate in prescription.Rates)
                {
                    if (rxRate.RxRate == null || !rxRate.RxRate.Any())
                    {
                        //If there is null or no rate, write the previous rate (or 0 if we have not yet entered a valid rate)
                        binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                    }
                    else
                    {
                        for (int index = 0; index < rxRate.RxRate.Count; index++)
                        {
                            var dataVariable = treatmentZone.Variables[index];
                            var rate         = rxRate.RxRate[index].Rate;
                            if (dataVariable.UserUnit != null)
                            {
                                rate = _unitConverter.Convert(dataVariable.UserUnit.ToInternalUom(), dataVariable.IsoUnit.ToAdaptUnit().ToInternalUom(), rate);
                            }

                            previousBytes = BitConverter.GetBytes((int)Math.Round(dataVariable.IsoUnit.ConvertToIsoUnit(rate), 0));
                            binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                        }
                    }
                }
            }

            return(gridFileName);
        }