LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Parse text and identify which column(s) contain non-matching data

Solved!
Go to solution

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

Message Edited by Ray.R on 10-04-2009 09:47 PM
0 Kudos
Message 1 of 8
(3,806 Views)
Solution
Accepted by topic author Ray.R
Ray, string aspect makes me think it is a memory dump, so I designed a solution that scans integer values from the string and operates on them, instead of working on the string itself. Take a look at the attached sample that should be what you are looking for; feel free to add comments or ask clarifications on some instruction if you need them.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 8
(3,793 Views)

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 

0 Kudos
Message 3 of 8
(3,783 Views)

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*

0 Kudos
Message 4 of 8
(3,742 Views)
Oh.. and yes, I did change the 0xAA to 0xA5 in the rest of the code (actually, it became a parameter)  😉
0 Kudos
Message 5 of 8
(3,741 Views)

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");



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 8
(3,733 Views)

Roberto beat me to it, but for what it's worth, here's my version:

 

 

for (str1 = strtok (pcTestData, "\n"); str1; str1 = strtok (NULL, "\n"))
    if (FindPattern (str1, 8, 1, ":", 0, 0) >= 0)
        Scan (str1, "%s[dt32]%16x[x]", d[i++]);

 

 

NickB

National Instruments  

Message 7 of 8
(3,719 Views)

Many thanks guys.

 

🙂

0 Kudos
Message 8 of 8
(3,708 Views)