10-04-2009 08:45 PM - edited 10-04-2009 08:47 PM
Hi everyone,
I want to write an elegant solution in LabWindows-CVI to accomplish the same as what I implemented in LabVIEW.
The client does not use or own LabVIEW. I must code the solution in CVI.
In order to simpify the explanation of what it is that I attempt to do, I wrote a quick example in LabVIEW (see below):
The code needs to parse a string to identify which column of data has non-matching elements. In order to do so, I first removed the unwanted text at the top and bottom. I also removed the additional space between the 2 groups of data by replacing the two spaced with a single one to make the next step easier. The resulting string was converted to a 2D array of string. Only the desired columns to be searched were kept (total of 16 columns). The 2D array was transposed because the search 1D array searched each row, whereas I want to search each column. The entire transposed 2D array was searched for any non-matching values, which populates a 1D array of boolean. I converted the 1D array of boolean to a number to see if any "non-matching data" was found. If none were found, then the value would be zero.
I need help coding this into CVI.
Many thanks,
RayR
Solved! Go to Solution.
10-05-2009 02:10 AM
10-05-2009 08:42 AM
Many thanks Roberto,
Your code example certainly meets the "Beautiful Code" criteria. 🙂
It's a very elegant approach, which would even make LabVIEW blush. 😉
Best Regards,
RayR
10-06-2009 03:45 PM
I need a bit more help.
The data in my case is not from a file, but rather passed by a pointer from the calling function (pcTestData)
I tried to use tokens to seperate each line and use it withinthe code you provided, but I keep running into some strange problem.... it doesn't work.. 😞
Here's the portion of code which fills up int d[16][16]
str1 = strtok(pcTestData, "\n");
/* loop until finishied */
while (!done)
{
/* extract string from string sequence */
str1 = strtok(NULL, "\n");
if (FindPattern (str1, 0, 10, "48", 0, 0) >= 0)
{
Scan (str1, "%s[dxt32]%16x[x]", d[i++]);
}
/* check if there is nothing else to extract */
if (str1 == NULL)
{
MessagePopup ("> Tokens <", "Token are complete");
done = TRUE;
}
x++;
}
Below is the actual data:
d 48000000 100
48000000: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000010: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000020: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000030: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000040: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000050: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000060: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000070: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000080: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
48000090: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000A0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000B0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000C0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000D0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000E0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
480000F0: A5 A5 A5 FF A5 A5 A5 A5 A5 A5 A5 FF A5 A5 A5 A5 ................
40000000*
10-06-2009 03:46 PM
10-06-2009 04:30 PM
I cannot test here, but I can see problems with the "48" appearing in the first row: it will be detected even if not at the beginning of the row since you are searching into the first 10 characters of the string; on the other hand, it appears that you are skipping the first token (line) since in the loop you immediately select another token. I would organize the code this way:
/* extract string from string sequence */
str1 = strtok (pcTestData, "\n");
i = 0;
/* loop until finished */
while (str1)
{
if (FindPattern (str1, 0, 3, "48", 0, 0) >= 0)
{
Scan (str1, "%s[dxt32]%16x[x]", d[i++]);
}
/* find if there are more tokens */
str1 = strtok (NULL, "\n");
}
// No more tokens to scan
MessagePopup ("> Tokens <", "Token are complete");
10-06-2009 04:55 PM
Roberto beat me to it, but for what it's worth, here's my version:
NickB
National Instruments
10-06-2009 08:12 PM
Many thanks guys.
🙂