openPQDIF Usage Example
This example shows how to use the GSF.PQDIF library by loading a PQDIF file and accessing different elements of the PQDIF file structure.
First, we need to include the following reference in our project code:
We can parse the information contained in the file and store it as a list of observation records.
List<ObservationRecord> observationRecords = new List<ObservationRecord>();
using (LogicalParser logicalParser = new LogicalParser(dialog.FileName))
Observation records have references to their data source and monitor settings records, and various elements can be accessed via properties to those objects.
ObservationRecord observation = observationRecords;
DataSourceRecord dataSource = observation.DataSource;
MonitorSettingsRecord monitorSettings = observation.Settings;
DateTime startTime = observation.StartTime;
string sourceName = dataSource.DataSourceName;
double nominalFrequency = monitorSettings.NominalFrequency;
Channel instances can also be accessed through the observation record, and series instances can be accessed through channel instances.
IList<ChannelInstance> channels = observation.ChannelInstances;
IList<SeriesInstance> series = channels.SeriesInstances;
Finally, the values for a particular series can be obtained through the OriginalValues property of the series instances. The type of these original values depends on the physical type of the values, scale, and offset defined in the PQDIF file and are thus
returned as a list of objects, but most types can be safely converted to double.
IList<object> originalValues = series.OriginalValues;
IEnumerable<double> values = originalValues.Select(Convert.ToDouble);