Exemplo n.º 1
0
        private bool ParseN42File()
        {
            if (radInstrumentData == null || deviceData == null)
            {
                return(false);
            }

            try {
                var instrumentInfo = radInstrumentData.RadInstrumentInformation;
                if (instrumentInfo == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = instrumentInfo.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = instrumentInfo.RadInstrumentIdentifier;

                // Get needed nodes AnalysisResultsType and RadMeasurementType
                var itemsElementNames = radInstrumentData.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }
                AnalysisResultsType analysisResultsType = null;
                DerivedDataType     derivedDataType = null;
                bool analysisFound = false, derivedDataFound = false;
                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    if (analysisFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.AnalysisResults)
                        {
                            analysisResultsType = radInstrumentData.Items[i] as AnalysisResultsType;
                            analysisFound       = true;
                        }
                    }

                    if (derivedDataFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.DerivedData)
                        {
                            derivedDataType = radInstrumentData.Items[i] as DerivedDataType;
                            // Check if correct node
                            if (derivedDataType.id.Contains("ProcessedData"))
                            {
                                derivedDataFound = true;
                            }
                        }
                    }

                    if (analysisFound && analysisFound)
                    {
                        break;
                    }
                }

                if (derivedDataFound == false || analysisFound == false)
                {
                    return(false);
                }

                // Get StartDateTime
                deviceData.StartDateTime = derivedDataType.StartDateTime;

                // Get MeaureTime
                string value     = derivedDataType.RealTimeDuration.Remove(0, 2);
                value = value.Remove(value.Length - 1, 1).Split('.').FirstOrDefault();
                deviceData.MeasureTime = new TimeSpan(0, 0, int.Parse(value));

                // Get Identified Nuclides
                int nuclideIndex = 0;
                var nuclides     = analysisResultsType.NuclideAnalysisResults.Nuclide;
                for (int i = 0; i < nuclides.Count(); i += 1)
                {
                    // Check if the nuclide was identified
                    if (nuclides[i].NuclideIdentifiedIndicator == false)
                    {
                        continue;
                    }

                    var elementNames = nuclides[i].ItemsElementName;
                    for (int c = 0; c < elementNames.Length; c += 1)
                    {
                        if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                        {
                            deviceData.Nuclides[nuclideIndex++] = new NuclideID(
                                nuclides[i].NuclideName, (double)nuclides[i].Items[c]);
                            break;
                        }
                    }
                }


                // Get CountRate
                var grossCountAnalysisResults = analysisResultsType.GrossCountAnalysisResults;
                if (grossCountAnalysisResults == null)
                {
                    return(true);
                }
                deviceData.CountRate = grossCountAnalysisResults.AverageCountRateValue.Value;
            }
            catch (Exception ex) {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private bool ParseN42File()
        {
            if (radInstrumentDataType == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                var radInstrumentInformationType = radInstrumentDataType.RadInstrumentInformation;
                if (radInstrumentInformationType == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = radInstrumentInformationType.RadInstrumentManufacturerName + " " + radInstrumentInformationType.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = radInstrumentInformationType.RadInstrumentIdentifier;

                // Get needed nodes AnalysisResultsType and DerivedDataType
                var itemsElementNames = radInstrumentDataType.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }
                AnalysisResultsType analysisResultsType = null;
                DerivedDataType     derivedDataType = null;
                bool analysisFound = false, derivedDataFound = false;
                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    if (analysisFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.AnalysisResults)
                        {
                            analysisResultsType = radInstrumentDataType.Items[i] as AnalysisResultsType;
                            analysisFound       = true;
                        }
                    }

                    if (derivedDataFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.DerivedData)
                        {
                            derivedDataType = radInstrumentDataType.Items[i] as DerivedDataType;
                            // Check if correct node
                            if (derivedDataType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                            {
                                derivedDataFound = true;
                            }
                        }
                    }

                    if (analysisFound && derivedDataFound)
                    {
                        break;
                    }
                }

                if (derivedDataFound == true) //"GC-PVT-BMCA-02161015-FG"
                {
                    // Get StartTime
                    deviceData.StartDateTime = derivedDataType.StartDateTime;

                    // Get MeasureTime
                    string value       = derivedDataType.RealTimeDuration.Remove(0, 2);
                    var    mIndex      = value.IndexOf("M");
                    var    sIndex      = value.IndexOf("S");
                    var    periodIndex = value.IndexOf(".");
                    if (mIndex != -1 && periodIndex != -1 && sIndex != -1)
                    {
                        deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0,
                                                                                         int.Parse(value.Substring(0, mIndex)),
                                                                                         int.Parse(value.Substring(mIndex + 1, periodIndex - mIndex - 1)),
                                                                                         int.Parse(value.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                    }
                    else if (mIndex != -1 && sIndex != -1)
                    {
                        deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0,
                                                                                         int.Parse(value.Substring(0, mIndex)),
                                                                                         int.Parse(value.Substring(mIndex + 1, sIndex - mIndex - 1))));
                    }
                    else if (mIndex != -1)
                    {
                        deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, int.Parse(value.Substring(0, mIndex)), 0));
                    }
                    else if (periodIndex != -1 && sIndex != -1)
                    {
                        deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, 0,
                                                                                         int.Parse(value.Substring(0, periodIndex)),
                                                                                         int.Parse(value.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                    }
                    else if (sIndex != -1)
                    {
                        deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, int.Parse(value.Substring(0, sIndex))));
                    }

                    // Get CountRate
                    foreach (var grossCounts in derivedDataType.GrossCounts)
                    {
                        if (grossCounts.id == "GC-M800-100732-FG")
                        {
                            deviceData.CountRate = double.Parse(grossCounts.CountData);
                            break;
                        }
                    }
                }

                if (analysisFound == true)
                {
                    //Get Identified Nuclides
                    if (analysisResultsType.NuclideAnalysisResults != null)
                    {
                        var nuclides = analysisResultsType.NuclideAnalysisResults.Nuclide;
                        for (int i = 0; i < nuclides.Count(); i += 1)
                        {
                            var elementNames = nuclides[i].ItemsElementName;
                            for (int c = 0; c < elementNames.Length; c += 1)
                            {
                                if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                                {
                                    deviceData.Nuclides[i] = new NuclideID(nuclides[i].NuclideName.Replace('_', '-'), double.Parse((string)nuclides[i].Items[c]));
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        private bool ParseN42File()
        {
            if (radInstrumentDataType == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                var radInstrumentInformationType = radInstrumentDataType.RadInstrumentInformation;
                if (radInstrumentInformationType == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = radInstrumentInformationType.RadInstrumentManufacturerName + " " + radInstrumentInformationType.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = radInstrumentInformationType.RadInstrumentIdentifier;

                // Get needed nodes AnalysisResultsType and DerivedDataType
                var itemsElementNames = radInstrumentDataType.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }
                AnalysisResultsType analysisResultsType = null;
                DerivedDataType     derivedDataType = null;
                RadMeasurementType  radMeasurementType = null;
                bool analysisFound = false, derivedDataFound = false, radMeasurementFound = false;
                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    if (analysisFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.AnalysisResults)
                        {
                            analysisResultsType = radInstrumentDataType.Items[i] as AnalysisResultsType;
                            if (analysisResultsType.NuclideAnalysisResults != null)
                            {
                                analysisFound = true;
                            }
                        }
                    }
                    if (derivedDataFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.DerivedData)
                        {
                            derivedDataType = radInstrumentDataType.Items[i] as DerivedDataType;
                            // Check if correct node
                            if (derivedDataType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                            {
                                derivedDataFound = true;
                            }
                        }
                    }

                    if (radMeasurementFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.RadMeasurement)
                        {
                            radMeasurementType = radInstrumentDataType.Items[i] as RadMeasurementType;
                            // Check if correct node
                            if (radMeasurementType.id == "ForegroundMeasureSum")
                            {
                                radMeasurementFound = true;
                            }
                        }
                    }

                    if (analysisFound && derivedDataFound && radMeasurementFound)
                    {
                        break;
                    }
                }

                if (derivedDataFound == true)
                {
                    // Get StartTime
                    deviceData.StartDateTime = derivedDataType.StartDateTime;

                    // Get MeasureTime
                    string value = derivedDataType.RealTimeDuration.Remove(0, 2);
                    value = value.Remove(value.Length - 1, 1);
                    deviceData.MeasureTime = new TimeSpan(0, 0, (int)Math.Round(double.Parse(value)));
                }

                // Get CountRate
                List <int> grossCounts = new List <int>();
                foreach (var grossCountValue in radMeasurementType.GrossCounts)
                {
                    int  value;
                    bool castSuccess = int.TryParse(grossCountValue.CountData, out value);
                    if (castSuccess)
                    {
                        grossCounts.Add(int.Parse(grossCountValue.CountData));
                    }
                    else
                    {
                        return(false);
                    }
                }
                deviceData.CountRate = grossCounts.Max();

                // Get Identified Nuclides
                if (analysisFound == true)
                {
                    var nuclides = analysisResultsType.NuclideAnalysisResults.Nuclide;
                    for (int i = 0; i < nuclides.Count(); i += 1)
                    {
                        var elementNames = nuclides[i].ItemsElementName;
                        for (int c = 0; c < elementNames.Count(); c += 1)
                        {
                            if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                            {
                                deviceData.Nuclides[i] = new NuclideID(nuclides[i].NuclideName, (double)nuclides[i].Items[c]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
        private bool ParseN42File()
        {
            if (radInstrumentDataType == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                var radInstrumentInformationType = radInstrumentDataType.RadInstrumentInformation;
                if (radInstrumentInformationType == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = radInstrumentInformationType.RadInstrumentManufacturerName + " " + radInstrumentInformationType.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = radInstrumentInformationType.RadInstrumentIdentifier;

                // Get needed nodes AnalysisResultsType and DerivedDataType
                var itemsElementNames = radInstrumentDataType.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }
                var             analysisResultsTypes = new List <AnalysisResultsType>();
                DerivedDataType derivedDataType = null;
                bool            analysisFound = false, derivedDataFound = false;
                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    switch (itemsElementNames[i])
                    {
                    case ItemsChoiceType2.AnalysisResults:
                        var analysisResultsType = radInstrumentDataType.Items[i] as AnalysisResultsType;
                        if (analysisResultsType.NuclideAnalysisResults != null)
                        {
                            analysisResultsTypes.Add(analysisResultsType);
                            analysisFound = true;
                        }
                        break;

                    case ItemsChoiceType2.DerivedData:
                        if (derivedDataFound == false)
                        {
                            var derivedData = radInstrumentDataType.Items[i] as DerivedDataType;
                            // Check if correct node
                            if (derivedData.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                            {
                                derivedDataType  = derivedData;
                                derivedDataFound = true;
                            }
                        }
                        break;
                    }
                }

                if (derivedDataFound == true)
                {
                    // Get StartTime
                    deviceData.StartDateTime = derivedDataType.StartDateTime;
                    // Get MeasureTime
                    string value = derivedDataType.RealTimeDuration.Remove(0, 2);
                    value = value.Remove(value.Length - 1, 1);
                    deviceData.MeasureTime = new TimeSpan(0, 0, (int)Math.Round(double.Parse(value)));
                    // Get CountRate
                    foreach (var grossCounts in derivedDataType.GrossCounts)
                    {
                        if (grossCounts.id == "ForegroundSumBox4NNS1")
                        {
                            deviceData.CountRate = double.Parse(grossCounts.CountData);
                            break;
                        }
                    }
                }
                // Get Identified Nuclides
                if (analysisFound == true)
                {
                    // Get every single nuclide found
                    var allNuclides = new List <NuclideID>();
                    foreach (var analysisResultsType in analysisResultsTypes)
                    {
                        var nuclides = analysisResultsType.NuclideAnalysisResults.Nuclide;
                        for (int i = 0; i < nuclides.Count(); i += 1)
                        {
                            var elementNames = nuclides[i].ItemsElementName;
                            for (int c = 0; c < elementNames.Count(); c += 1)
                            {
                                if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                                {
                                    allNuclides.Add(new NuclideID(nuclides[i].NuclideName, (double)nuclides[i].Items[c]));
                                }
                            }
                        }
                    }
                    // Only get distinct nuclides
                    allNuclides = allNuclides
                                  .DistinctBy(x => x.NuclideName)
                                  .OrderBy(x => x.NuclideName)
                                  .ToList();
                    for (int i = 0; i < allNuclides.Count; i += 1)
                    {
                        deviceData.Nuclides[i] = allNuclides[i];
                    }
                }
            }
            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        private bool ParseN42File()
        {
            if (radInstrumentDataType == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                var radInstrumentInformationType = radInstrumentDataType.RadInstrumentInformation;
                if (radInstrumentInformationType == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = radInstrumentInformationType.RadInstrumentManufacturerName + " " + radInstrumentInformationType.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = radInstrumentInformationType.RadInstrumentIdentifier;

                // Get needed nodes AnalysisResultsType and RadMeasurementType
                var itemsElementNames = radInstrumentDataType.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }

                AnalysisResultsType        analysisResultsType = null;
                RadMeasurementType         radMeasurementType = null;
                List <AnalysisResultsType> analysisResultsList = new List <AnalysisResultsType>();
                List <DerivedDataType>     derivedDataList = new List <DerivedDataType>();
                List <RadMeasurementType>  radMeasurementList = new List <RadMeasurementType>();
                bool analysisFound = false, derivedDataFound = false, radMeasurementFound = false;

                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    if (itemsElementNames[i] == ItemsChoiceType2.AnalysisResults)
                    {
                        analysisResultsType = radInstrumentDataType.Items[i] as AnalysisResultsType;
                        analysisResultsList.Add(analysisResultsType);
                        analysisFound = true;
                    }

                    if (itemsElementNames[i] == ItemsChoiceType2.DerivedData)
                    {
                        DerivedDataType tempDerivedDataType = radInstrumentDataType.Items[i] as DerivedDataType;
                        // Check if correct node
                        if (tempDerivedDataType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                        {
                            derivedDataList.Add(tempDerivedDataType);
                        }
                        derivedDataFound = true;
                    }

                    if (itemsElementNames[i] == ItemsChoiceType2.RadMeasurement)
                    {
                        radMeasurementType = radInstrumentDataType.Items[i] as RadMeasurementType;
                        // Check if correct node
                        if (radMeasurementType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                        {
                            radMeasurementList.Add(radMeasurementType);
                        }
                        radMeasurementFound = true;
                    }
                }

                if (derivedDataFound)
                {
                    // Get StartTime
                    deviceData.StartDateTime = derivedDataList[0].StartDateTime;

                    // Get MeasureTime
                    deviceData.MeasureTime = new TimeSpan(0, 0, 0);
                    foreach (DerivedDataType item in derivedDataList)
                    {
                        string time        = item.RealTimeDuration.Remove(0, 2);
                        var    mIndex      = time.IndexOf("M");
                        var    sIndex      = time.IndexOf("S");
                        var    periodIndex = time.IndexOf(".");
                        if (mIndex != -1 && periodIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0,
                                                                                             int.Parse(time.Substring(0, mIndex)),
                                                                                             int.Parse(time.Substring(mIndex + 1, periodIndex - mIndex - 1)),
                                                                                             int.Parse(time.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                        }
                        else if (mIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0,
                                                                                             int.Parse(time.Substring(0, mIndex)),
                                                                                             int.Parse(time.Substring(mIndex + 1, sIndex - mIndex - 1))));
                        }
                        else if (mIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, int.Parse(time.Substring(0, mIndex)), 0));
                        }
                        else if (periodIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, 0,
                                                                                             int.Parse(time.Substring(0, periodIndex)),
                                                                                             int.Parse(time.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                        }
                        else if (sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, int.Parse(time.Substring(0, sIndex))));
                        }
                    }
                }

                // Get CountRate
                if (radMeasurementFound)
                {
                    int sumCountData = 0;
                    foreach (RadMeasurementType item in radMeasurementList)
                    {
                        foreach (GrossCountsType grossCounts in item.GrossCounts)
                        {
                            int  num;
                            bool castSuccess = int.TryParse(grossCounts.CountData, out num);
                            if (castSuccess)
                            {
                                sumCountData += num;
                            }
                        }
                    }
                    deviceData.CountRate = sumCountData;
                }

                // Get Identified Nuclides
                if (analysisFound == true)
                {
                    List <NuclideType> nuclideResults = new List <NuclideType>();

                    //Add first nuclide to the result list
                    foreach (NuclideType nucResult in analysisResultsList[0].NuclideAnalysisResults.Nuclide)
                    {
                        if (nucResult.ItemsElementName[0] == ItemsChoiceType.NuclideIDConfidenceValue)
                        {
                            nuclideResults.Add(nucResult);
                        }
                    }
                    int val = analysisResultsList.Count();
                    for (int i = 1; i < analysisResultsList.Count() - 1; i += 1)
                    {
                        foreach (NuclideType nuclide in analysisResultsList[i].NuclideAnalysisResults.Nuclide)
                        {
                            foreach (NuclideType nucResult in nuclideResults)
                            {
                                //Add nuclides to result list if the nuclide is not in the list
                                if (nuclide.NuclideName != nucResult.NuclideName && nuclide.ItemsElementName[0] == ItemsChoiceType.NuclideIDConfidenceValue)
                                {
                                    nuclideResults.Add(nuclide);
                                    break;
                                }
                                //Updates the confidence value for a nuclide if a larger value is found
                                else if (nuclide.NuclideName == nucResult.NuclideName &&
                                         nuclide.ItemsElementName[0] == ItemsChoiceType.NuclideIDConfidenceValue &&
                                         ((double)nuclide.Items[0] > (double)nucResult.Items[0]))
                                {
                                    nuclideResults.Remove(nucResult);
                                    nuclideResults.Add(nuclide);
                                    break;
                                }
                            }
                        }
                    }
                    //Add nuclides to deviceData
                    for (int i = 0; i < nuclideResults.Count(); i += 1)
                    {
                        var elementNames = nuclideResults[i].ItemsElementName;
                        for (int c = 0; c < elementNames.Length; c += 1)
                        {
                            if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                            {
                                deviceData.Nuclides[i] = new NuclideID(nuclideResults[i].NuclideName, (double)nuclideResults[i].Items[c]);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        private bool ParseN42File()
        {
            if (radInstrumentData == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                RadInstrumentInformationType instrumentInfo = radInstrumentData.RadInstrumentInformation;
                if (instrumentInfo == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = instrumentInfo.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = instrumentInfo.RadInstrumentIdentifier.Split('-').LastOrDefault();

                // Find AnalysisResults and DerivedData
                AnalysisResultsType analysisResults = null;
                DerivedDataType     derivedData     = null;
                ItemsChoiceType2[]  itemsChoices2   = radInstrumentData.ItemsElementName;
                for (int i = itemsChoices2.Length - 1; i >= 0; i -= 1)
                {
                    if (analysisResults == null)
                    {
                        if (itemsChoices2[i] == ItemsChoiceType2.AnalysisResults)
                        {
                            analysisResults = radInstrumentData.Items[i] as AnalysisResultsType;
                            // Check if correct Id
                            if (analysisResults.id.StartsWith("Identification") == true)
                            {
                                continue;
                            }
                            analysisResults = null;
                        }
                    }
                    if (derivedData == null)
                    {
                        if (itemsChoices2[i] == ItemsChoiceType2.DerivedData)
                        {
                            derivedData = radInstrumentData.Items[i] as DerivedDataType;
                            // Check if correct Id
                            if (derivedData.id.StartsWith("ForegroundMeasureSum") == true)
                            {
                                continue;
                            }
                            derivedData = null;
                        }
                    }
                    if (analysisResults != null && derivedData != null)
                    {
                        break;
                    }
                }

                // Get StartDateTime
                if (analysisResults == null || analysisResults.AnalysisStartDateTimeSpecified == false)
                {
                    return(false);
                }
                deviceData.StartDateTime = analysisResults.AnalysisStartDateTime;

                // Get Identified Nuclides
                if (analysisResults.NuclideAnalysisResults == null)
                {
                    return(true);
                }
                NuclideType[] nuclides = analysisResults.NuclideAnalysisResults.Nuclide;
                if (nuclides == null)
                {
                    return(true);
                }
                for (int i = 0; i < nuclides.Length; i += 1)
                {
                    double            confidence   = -1;
                    ItemsChoiceType[] itemsChoices = nuclides[i].ItemsElementName;
                    for (int c = 0; c < itemsChoices.Length; c += 1)
                    {
                        if (itemsChoices[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                        {
                            confidence = (double)nuclides[i].Items[c];
                            break;
                        }
                    }
                    deviceData.Nuclides[i] = new NuclideID(
                        nuclides[i].NuclideName, confidence);
                }

                // Get MeasureTime
                if (derivedData == null)
                {
                    return(false);
                }
                // Format is PTsss.fffS
                string value = derivedData.RealTimeDuration.Remove(0, 2);
                value = value.Remove(value.Length - 1, 1);
                deviceData.MeasureTime = new TimeSpan(0, 0, (int)Math.Round(double.Parse(value)));

                // Get Count Rate
                SpectrumType spectrumType = derivedData.Spectrum.Where(s => s.id == "ForegroundSumGamma").FirstOrDefault();
                if (spectrumType == null)
                {
                    return(false);
                }
                // Sum spectrum and divide by MeasureTime
                int sum = spectrumType.ChannelData.Text.Split(Globals.Delim_Space, StringSplitOptions.RemoveEmptyEntries).Sum(c => int.Parse(c));
                deviceData.CountRate = sum / deviceData.MeasureTime.TotalSeconds;
            }
            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        private bool ParseN42File()
        {
            if (radInstrumentDataType == null || deviceData == null)
            {
                return(false);
            }

            try
            {
                var radInstrumentInformationType = radInstrumentDataType.RadInstrumentInformation;
                if (radInstrumentInformationType == null)
                {
                    return(false);
                }

                // Get DeviceType
                deviceData.DeviceType = radInstrumentInformationType.RadInstrumentManufacturerName + " " + radInstrumentInformationType.RadInstrumentModelName;

                // Get SerialNumber
                deviceData.SerialNumber = radInstrumentInformationType.RadInstrumentIdentifier;

                // Get needed nodes and necessary data from AnalysisResultsType, DerivedDataType, and RadMeasurementType
                var itemsElementNames = radInstrumentDataType.ItemsElementName;
                if (itemsElementNames == null)
                {
                    return(false);
                }

                AnalysisResultsType analysisResultsType  = null;
                DerivedDataType     firstDerivedDataType = null;
                DerivedDataType     tempDerivedDataType  = null;
                RadMeasurementType  radMeasurementType   = null;

                List <DerivedDataType>    derivedDataTypes = new List <DerivedDataType>();
                List <RadMeasurementType> radMeasureTypes  = new List <RadMeasurementType>();

                bool analysisFound = false, firstDerivedDataFound = false;


                for (int i = 0; i < itemsElementNames.Count(); i += 1)
                {
                    if (analysisFound == false)
                    {
                        if (itemsElementNames[i] == ItemsChoiceType2.AnalysisResults)
                        {
                            analysisResultsType = radInstrumentDataType.Items[i] as AnalysisResultsType;
                            if (analysisResultsType.NuclideAnalysisResults != null)
                            {
                                analysisFound = true;
                            }
                        }
                    }

                    if (itemsElementNames[i] == ItemsChoiceType2.DerivedData)
                    {
                        if (firstDerivedDataFound == false)
                        {
                            firstDerivedDataType = radInstrumentDataType.Items[i] as DerivedDataType;
                            // Check if correct node
                            if (firstDerivedDataType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                            {
                                derivedDataTypes.Add(firstDerivedDataType);
                            }
                            firstDerivedDataFound = true;
                        }
                        else
                        {
                            tempDerivedDataType = radInstrumentDataType.Items[i] as DerivedDataType;
                            if (tempDerivedDataType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                            {
                                derivedDataTypes.Add(tempDerivedDataType);
                            }
                        }
                    }

                    if (itemsElementNames[i] == ItemsChoiceType2.RadMeasurement)
                    {
                        radMeasurementType = radInstrumentDataType.Items[i] as RadMeasurementType;
                        // Check if correct node
                        if (radMeasurementType.MeasurementClassCode == MeasurementClassCodeSimpleType.Foreground)
                        {
                            radMeasureTypes.Add(radMeasurementType);
                        }
                    }
                }

                if (firstDerivedDataFound == true)
                {
                    // Get StartTime
                    deviceData.StartDateTime = firstDerivedDataType.StartDateTime;

                    // Get MeasureTime
                    deviceData.MeasureTime = new TimeSpan(0, 0, 0);
                    foreach (DerivedDataType item in derivedDataTypes)
                    {
                        string time        = item.RealTimeDuration.Remove(0, 2);
                        var    mIndex      = time.IndexOf("M");
                        var    sIndex      = time.IndexOf("S");
                        var    periodIndex = time.IndexOf(".");
                        if (mIndex != -1 && periodIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0,
                                                                                             int.Parse(time.Substring(0, mIndex)),
                                                                                             int.Parse(time.Substring(mIndex + 1, periodIndex - mIndex - 1)),
                                                                                             int.Parse(time.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                        }
                        else if (mIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0,
                                                                                             int.Parse(time.Substring(0, mIndex)),
                                                                                             int.Parse(time.Substring(mIndex + 1, sIndex - mIndex - 1))));
                        }
                        else if (mIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, int.Parse(time.Substring(0, mIndex)), 0));
                        }
                        else if (periodIndex != -1 && sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, 0,
                                                                                             int.Parse(time.Substring(0, periodIndex)),
                                                                                             int.Parse(time.Substring(periodIndex + 1, sIndex - periodIndex - 1))));
                        }
                        else if (sIndex != -1)
                        {
                            deviceData.MeasureTime = deviceData.MeasureTime.Add(new TimeSpan(0, 0, int.Parse(time.Substring(0, sIndex))));
                        }
                    }
                }


                // Get CountRate
                int sumCountData = 0;
                foreach (RadMeasurementType item in radMeasureTypes)
                {
                    foreach (GrossCountsType grossCounts in item.GrossCounts)
                    {
                        int  num;
                        bool castSuccess = int.TryParse(grossCounts.CountData, out num);
                        if (castSuccess)
                        {
                            sumCountData += num;
                        }
                    }
                }
                deviceData.CountRate = sumCountData;

                //////// Need to edit this section to properly retrieve the nuclide results from analysisResults ////////
                // Get Identified Nuclides
                if (analysisFound == true)
                {
                    var nuclides = analysisResultsType.NuclideAnalysisResults.Nuclide;
                    for (int i = 0; i < nuclides.Count(); i += 1)
                    {
                        var elementNames = nuclides[i].ItemsElementName;
                        for (int c = 0; c < elementNames.Count(); c += 1)
                        {
                            if (elementNames[c] == ItemsChoiceType.NuclideIDConfidenceValue)
                            {
                                deviceData.Nuclides[i] = new NuclideID(nuclides[i].NuclideName, (double)nuclides[i].Items[c]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                fileErrors.Add(new KeyValuePair <string, string>(Path.GetFileName(deviceData.FileName), ex.Message));
                ErrorsOccurred = true;
                return(false);
            }
            return(true);
        }