Discussion:
DAQmx Read (2D), Write to Binary File, and Dimension Majority
(too old to reply)
Ryan Duguay
2008-07-15 21:40:08 UTC
Permalink
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...
Brooks_C
2008-07-18 15:40:10 UTC
Permalink
Hello Ryan,

 

According to this KnowledgeBase article, <a href="http://digital.ni.com/public.nsf/allkb/9AB6A4948D0B5B32862573E10081EA79?OpenDocument" target="_blank"> Passing 2D Arrays between LabVIEW and CVI or Measurement Studio with Network Variables</a>, LabVIEW is column-major.&nbsp; However, I've done similar testing to what you've done and I do agree that the Write Binary File VI does write the values with the row-major format (also important to note is that our Read Binary File VI also reads with row-major format).&nbsp; I know that C and most other programming languages do use row-major format and I would assume that we chose to do this to stay compatible with the standard, even if our memory addresses are actually column-major.&nbsp; If you do want to write the binary file in column-major format you can always use the Transpose 2D Array VI to transpose the array before you write it to the binary file.

&nbsp;

I hope this helps, and have a great day!

&nbsp;

Cheers,

Loading...