Issues parsing COMTRADE files (.cfg, .dat) with Gemstone.COMTRADE

Hello,

I’m just trying to figure how to use the Gemstone.COMTRADE library with a couple of COMTRADEs that I used with other COMTRADE view applications. I took some example code from the openXDA project:

IList<ParsedChannel> m_channels;
DateTime? startTime = null;


using (Parser parser = new Parser())
{
    parser.Schema = new Schema(@"<my comtrade file name>.cfg");
    parser.FileName = "<my comtrade file name>.dat";
    parser.InferTimeFromSampleRates = true;


    parser.OpenFiles();

    Console.WriteLine(parser.Schema.AnalogChannels.Length);
    m_channels = parser.Schema.AnalogChannels
        .Select(channel => new ParsedChannel()
        {
            Index = channel.Index,
            Name = ((object)channel.ChannelName != null) ? string.Format("{0} ({1})", channel.StationName, channel.ChannelName) : channel.StationName,
            TimeValues = new List<DateTime>(),
            XValues = new List<object>(),
            YValues = new List<object>()
        }).ToList();

    foreach (var channel in m_channels)
    {
        Console.WriteLine(channel.Name);
    }

    while (parser.ReadNext())
    {
        if ((object)startTime == null)
            startTime = parser.Timestamp;

        for (int i = 0; i < m_channels.Count; i++)
        {
            m_channels[i].TimeValues.Add(parser.Timestamp);
            m_channels[i].XValues.Add(parser.Timestamp.Subtract(startTime.Value).TotalSeconds);
            m_channels[i].YValues.Add(parser.Values[i]);
        }
    }

But it seems like the parser isn’t reading the .dat file because I keep getting this error:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Gemstone.COMTRADE.Parser.ReadNextBinary()
   at Gemstone.COMTRADE.Parser.ReadNext()
   at Program.<Main>$(String[] args) in <my directory>\Program.cs:line 38

Which is weird because when I console out the parser.FileName I do get the file name I gave it before I parser.OpenFiles().

Can anyone lend a hand? Am I doing the recommend procedure Gemstone.COMTRADE?

Hello Jeff,

This appears to be due to a bug in the parser specific to referencing files in the working directory via relative paths. As a workaround, you can use absolute paths or prefix the relative path with .\.

parser.Schema = new Schema(@".\<my comtrade file name>.cfg");
parser.FileName = @".\<my comtrade file name>.dat";

Thanks,
Stephen