02-16-2017 11:42 AM
Hey
I am working on developing a data plugin and I usually use the function GetStringBlock to get a block of data after a particular point in my data files.
however I now have a data file which has header information then a few lines of data then the next entry is a standard repeating header, followed by a few lines of data see below.
My question is how would I develop a plugin that would allow me to grab only the data and skip the repeated header information.
Can this be down using GetStringBlock function?
02-17-2017 04:17 AM
Hi Tim,
in your case you need to create a new StringBlock for each data section. Please note that you can set the length for a block with oBlock.BlockLength = 4.
You can concatenate all subchannels of each StringBlock using ProcessedChannels:
Dim da1 : Set da1 = oBlock1.Channels.Add("chn1_1", eR64) '... Dim da2 : Set da2 = oBlock2.Channels.Add("chn1_2", eR64) '... Dim oProcessedChannel : Set oProcessedChannel = oChannelGroup.Channels.AddProcessedChannel("chn1", eR64, eConcatProcessor) call oProcessedChannel.Channels.Add(da1) call oProcessedChannel.Channels.Add(da2)
Greetings
02-17-2017 09:42 AM
That'sexactly what I was looking for.
You wouldn't happen to know of a method to determine the number of rows or where the end of file occurs?
Currently I have my plugin hard coded to 50 iterations but it would be nice to have it continue until there is no more data to be read
For i = 0 to 49 Set oBlock4(i) = File.GetStringBlock() oBlock4(i).BlockLength = 4 Set chn1(i) = oBlock4(i).Channels.Add("chn1_"&i, eR64) Call File.SkipLines(9) Next Dim oProcessedChannel1 : Set oProcessedChannel1 = ChannelGroup.Channels.AddProcessedChannel("chn1", eR64, eConcatProcessor) For i = 0 to 49 call oProcessedChannel1.Channels.Add(chn1(i)) Next End If
02-17-2017 10:10 AM
The method File.SkipLines(i) returns the number of skipped lines, i.e. it will return a number less than i if you reach the end of the file. This could be a good stop criterion.
Dim oProcessedChannel1 : Set oProcessedChannel1 = ChannelGroup.Channels.AddProcessedChannel("chn1", eR64, eConcatProcessor) Dim nrOfSkippedLines : nrOfSkippedLines = 0 Do Set oBlock4 = File.GetStringBlock() oBlock4.BlockLength = 4 Set chn1 = oBlock4.Channels.Add("chn1", eR64) call oProcessedChannel1.Channels.Add(chn1) nrOfSkippedLines = File.SkipLines(9) Loop Until (nrOfSkpieedLines = 9)
02-17-2017 12:05 PM
Thanks again for the feedback.
My problem is I don't know how many lines I have until the end of file.
I am skipping lines by 9 to skip the repeating header data shown in a previous post.
I think it would be best to know how many lines are in the data file as it will let me know how many iterations of skipping 9 lines I will have to perform.
02-17-2017 01:20 PM
Hi Tim,
This is what I do to read through a file and determine when the lines stop. You can use the File.SkipLine command if you don't care to read the data while you go or the File.GetNextLine command if you want to analyze each line one at a time as you go.
DataPos = File.Position Do While File.Position < File.Size i = i + 1 Call File.SkipLine Loop ' Until EOF iMax = CLng(i) File.Position = DataPos Set Block = File.GetStringBlock() Block.BlockLength = iMax
Brad Turpin
DIAdem Product Support Engineer
National Instruments