Changing the value of an inserted point.

This section is looking through lines of data looking for missing lines using the timestamp(Tmstamp). When a gap in time is found one point is inserted (and made a zero). The value of the tmstamp[i] is then set to one minute less than the next larger time value. This section works. Then i enter  the for loop to add points to the other waves except the tmstamp wave. This works as well. Now I want to change the zeros that have been added to the other waves to -999 so that they can be identified when plotting. I cannot get this to work. I'm certain it's syntax. I've looked in the help files and they are not clear enough for me. I'm sure it has something to do with the wave reference but... Thanks for the help in advance. 

 

ssmith911

 

        ELSEIF ((t2 - t1)>60)
            INSERTPOINTS i,1,tmstamp        //If True insert point in front of index i, 1 point, in wave "tmpstamp"
            tmstamp[i] = (tmstamp[i+1] - 60)    //Changes the inserted zero to 60 seconds less than the following point.           
            //This FOR loop uses the missing time index from tmstamp to insert missing points into the data waves
            //Then it set those points -999.
            FOR(a=0; a<(itemsinlist(listowaves)); a+=1)
                WavNam = stringfromlist(a, listowaves)
                IF(CmpStr(wavnam, "TmStamp") != 0)  //When comparing strings one must use the CMPSTR function
                    INSERTPOINTS i, 1, $Wavnam
//                  wavnam[i] = (-999)

                ENDIF
            ENDFOR 

 

     INSERTPOINTS i, 1, $Wavnam
//   wavnam[i] = (-999)

     wave w=$wavnam
     w[i]=-999

 

Thanks Tony. Could you explain whats going on here and why it has to be done in this manner? Thanks again.

 

S

In reply to by ssmith911

ssmith911 wrote:

Could you explain whats going on here and why it has to be done in this manner? Thanks again.

 

Your code would have attempted to assign a numeric value (999) to a "WavNam", which is a string and not a wave (nor a numeric variable). You need to locally declare the wave whose name is stored in WavNam. That's what Tony's line, "wave w=$wavnam", does. It declares the wave whose name is stored in WavNam locally as wave w. Then you're able to make the assignment.

The "$" dereferences WavNam and returns the wave reference to the wave whose name is stored in WavNam. run displayhelptopic "wave references" for more info.

Your other line is similar

 INSERTPOINTS i, 1, $Wavnam

it would not have worked without the $ because insertpoints works on waves and not on strings.

Some functions like insertpoints do not require you to locally declare the wave, while setting point values in waves does.

 

 

In reply to by ssmith911

Sorry, I should have added a couple of lines of explanation.

This may help:

DisplayHelpTopic "Accessing Waves In Functions"
DisplayHelpTopic "Converting a String into a Reference Using $"

Another good reference is DisplayHelpTopic "Accessing Global Variables And Waves"

That explains the compile-time and run-time actions of a WAVE, NVAR or SVAR statement.

In reply to by ssmith911

If you're using Igor 8 you can set the value as you insert the point:

        ELSEIF ((t2 - t1)>60)          
            //This FOR loop uses the missing time index from tmstamp to insert missing points into the data waves
            FOR(a=0; a<(itemsinlist(listowaves)); a+=1)
                wave w = $(stringfromlist(a, listowaves)) // w references ath wave in listowaves
                INSERTPOINTS /V=-999 i, 1, w
            ENDFOR
            tmstamp[i] = (tmstamp[i+1] - 60) // Changes the inserted -999 to 60 seconds less than the following point.