Ryan Duguay
2008-07-15 21:40:08 UTC
I first apologize for being the one millionth customer to ask a "row major?" question on the one millionth message board. I realize there's is a lot of discussion about this out there, and I've read it, but I don't understand why I see what I see.My assumptions from various sources:1. Tradition in the world of programming dictates that 2D array indices are referred to as ["row","column"]; that is, the 1st dimension indexed is refered to as row, the 2nd as column.2. LabVIEW is "column-major"; that is, in linear memory, the 1st dimension (or row) of an array increments first (faster).I'm using NChan NSamp version of "DAQmx Read.vi" to grab m samples of n AI channels (NI-6254 M-Series). The documentation for this function states of the output:" data returns a 2D array of 16-bit signed integer samples. Each
element in the first dimension of the array corresponds to a channel in the
task. Each element in the second dimension of the array corresponds to a sample
from that channel. "From this documention and my assumptions, I would expect that in memory (and therefore when written to disk) the 2D array returned by "DAQmx Read.vi" would increment first by the "channel" dimension, followed by the "sample" dimension. This is also the order I would expect samples to physically arrive from the scanning multi-channel board.From "DAQmx Read.vi" I receive a 2D array: data[n -channels,m -samples], as expected. I write this array to disk with "Write to Binary File.vi", allowing the default input "Prepend Array Size?"=TRUE.When reading the file with MatLab or IDL (both column-major languages btw, but that's not important), the data begins with two 32-bit words representing the array size values of n and m respectively, as expected. I interpret this as "Write to Binary File.vi" telling me that the following data is an array of n rows by m columns, and knowing that LabVIEW handles arrays in a column-major fasion, I excted that the n rows of the data will increment first.At this point I expect the sample data to follow in order: [0Chan,0Samp] [1Chan,0Samp] ... [NChan,0Samp] ... [NChan, MSamp]What I actually find is data in the following order: [0Chan,0Samp] [0Chan,1Samp] ... [0Chan,MSamp] ... [NChan, MSamp]In other words, the file on disk contains data in the following order, linearly, m samples of channel 0, followed by m samples of channel 1, etc.Since the "samples" are the 2nd dimension of the array, yet sample number is clearly incrementing first, I'm lead to believe that LabVIEW is writing the array to disk in row-major order, but too many sources tell me otherwise. Where am I going wrong? I've attached an image showing how I'm writing the data output from "DAQmx Read.vi" directly to "Write to Binary File.vi". I don't currently have access to my development system to isolate the code in a simple VI.Thanks
DAQmxReadWriteFile2.JPG:
Loading Image...
element in the first dimension of the array corresponds to a channel in the
task. Each element in the second dimension of the array corresponds to a sample
from that channel. "From this documention and my assumptions, I would expect that in memory (and therefore when written to disk) the 2D array returned by "DAQmx Read.vi" would increment first by the "channel" dimension, followed by the "sample" dimension. This is also the order I would expect samples to physically arrive from the scanning multi-channel board.From "DAQmx Read.vi" I receive a 2D array: data[n -channels,m -samples], as expected. I write this array to disk with "Write to Binary File.vi", allowing the default input "Prepend Array Size?"=TRUE.When reading the file with MatLab or IDL (both column-major languages btw, but that's not important), the data begins with two 32-bit words representing the array size values of n and m respectively, as expected. I interpret this as "Write to Binary File.vi" telling me that the following data is an array of n rows by m columns, and knowing that LabVIEW handles arrays in a column-major fasion, I excted that the n rows of the data will increment first.At this point I expect the sample data to follow in order: [0Chan,0Samp] [1Chan,0Samp] ... [NChan,0Samp] ... [NChan, MSamp]What I actually find is data in the following order: [0Chan,0Samp] [0Chan,1Samp] ... [0Chan,MSamp] ... [NChan, MSamp]In other words, the file on disk contains data in the following order, linearly, m samples of channel 0, followed by m samples of channel 1, etc.Since the "samples" are the 2nd dimension of the array, yet sample number is clearly incrementing first, I'm lead to believe that LabVIEW is writing the array to disk in row-major order, but too many sources tell me otherwise. Where am I going wrong? I've attached an image showing how I'm writing the data output from "DAQmx Read.vi" directly to "Write to Binary File.vi". I don't currently have access to my development system to isolate the code in a simple VI.Thanks
DAQmxReadWriteFile2.JPG:
Loading Image...