search for matching text iteratively through a text wave

I have three waves 1. text , 2. date, 3. numeric. I wrote some code but am having trouble with the part where I am trying to iterate through the text wave, point by point and search for target text. Any help is appreciated.

 

What I am trying to accomplish is:

 

1. If the PID is the same 2+ times in a row (not unique), but all corresponding (same row) dates are the same, store the most recent date from all rows where PID is the same, while removing duplicate rows

2. If the PID is the same 2+ times in a row (not unique), and all dates are different, check the text wave for a corresponding matching string "arc", then store this date else, store most recent date while removing duplicate rows

3. If the PID is unique (no difference between 2 adjacent row) - keep the corresponding date

The idea is two have only unique PIDs, each with a date (real date wave) that matched the criteria 1-3

 

 

function filt()


wave pid
variable i = 0
wave test_date
wave/t test_type
string temp


wave real_date ///create wave to keep the latest date

Make /O/N = (numpnts(pid)) real_date

do

    if(pid[i+1] == pid[i])
        if(test_date[i+1] == test_date[i])
            real_date[i] = test_date[i+1]
            i+=1
        elseif(test_date[i+1] != test_date[i])
            if(GrepString(temp,"(?i)arc"))
                real_date[i] = test_date[i+1]                       //matches src
                i+=1
            else
                real_date[i] = test_date[i]
                i+=1
            endif
        endif
    else
        real_date[i] = test_date[i+1]
        i+=1                //does not match
    endif
           


while(i<(numpnts(pid)))



end

 

Picture of first row of the 3 waves I am using

Upload example waves for this, and I'll take a look.

As I read it, task 1 and 2 reduce to the same thing.

Your loop is pretty untidy, with lots of redundant i= i+1 statments, and a bad loop termination, since when i = numpnts(pid)-1, test_date[i+1] will be beyond the bounds of the wave (presuming the waves all have the same length).

I don't understand the search task, but you can do simple indexing using wave assignments rather than loops, e.g. 

Make/O/N=(numPnts(pid1)) pid_idx=0, type_idx=0

// set index to 1 where duplicates occur
pid_idx[1,] = pid[p] == pid[p-1]

// set text index to 1 where *ARC* occurs
type_idx = stringMatch(test_type1[p], "*ARC*")

maybe this helps along the way...

i think your logic translates to this:

// assumes waves are sorted by increasing date
function filt()
    wave pid
    wave test_date
    wave /T test_type
   
    int i, pnt2delete
   
    for (i=numpnts(pid)-1;i>0;i--)
        if (pid[i] != pid[i-1])
            continue
        elseif (test_date[i] == test_date[i-1])
            pnt2delete = i-1
        elseif (stringmatch(test_type[i-1], "*arc*"))
            pnt2delete = i
        else
            pnt2delete = i-1
        endif
        DeletePoints pnt2delete, 1, pid, test_date, test_type
    endfor
end