Slider control for XY data does not work on waveform...how to do that ?

I use the following slider control code (thanks to "hrodstein") for applying slider control over a XY data ( actually to shift Y value ..like say Y=Y+5 through slider) and it works very well..but it does not work on waveform data like data created (fit_XData.x and fit_XData.d ) after doing a Gaussian fit on such XY data.

My question is what changes I need to do to have applicable also on waveform data.

Function/DF GetSupraPackageDFR()
    DFREF dfr = root:Packages:Supra
    if (DataFolderRefStatus(dfr) != 1)
        NewDataFolder /O root:Packages
        NewDataFolder /O root:Packages:Supra
        DFREF dfr = root:Packages:Supra
        Variable/G dfr:gLastSliderValueAdded = 0
    endif
    return dfr
End

Function AddSliderValue(xWave, yWave, startX, endX, sliderValue)
    Wave xWave, yWave
    Variable startX, endX
    Variable sliderValue
   
    // Take the previously-added slider value, if any, into account
    DFREF dfr = GetSupraPackageDFR()
    NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded

    // To avoid accumulation of roundoff error we do this in two steps
    YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
    YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0

    gLastSliderValueAdded = sliderValue
End
[/quote]
supra wrote:
I use the following slider control code ... My question is what changes I need to do to have applicable also on waveform data. ...


You might look in to the function x2pnt, leading I think to the following or its equivalent:

variable ps, pe
ps = x2pnt(ywave,startx)
pe = x2pnt(ywave,endx)
ywave[ps,pe] -= gLastSliderValueAdded
ywave[ps,pe] += slidervalue


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Or alter the original code like this:
    if (WaveExists(xWave))
        YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
        YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
    else
        YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
        YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
    endif

JJWeimer's use of a variable to hold the result of pnt2x() would be a bit faster, but I don't think it will be noticeable in this application.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thanks to jjweimer and Johnweeks...I used the following as suggested by Johnweeks and weimer...also I fogot to mention that in the main code I also have a option to put cursor on the data ( wave or XY) ..so that I can select a particular wave or XY data out of many wave / or XY and then can move the segment of the wave/XY ( usually the whole graph by putting the cursor at ends) by moving the slider.
Somehow I still didnt able to make it work on wave data.

   
Function/DF GetSupraPackageDFR()
    DFREF dfr = root:Packages:Supra
    if (DataFolderRefStatus(dfr) != 1)
        NewDataFolder /O root:Packages
        NewDataFolder /O root:Packages:Supra
        DFREF dfr = root:Packages:Supra
        Variable/G dfr:gLastSliderValueAdded = 0
    endif
    return dfr
End


Function MoveSegment(SliderValue)

    Variable SliderValue

 // Take the previously-added slider value, if any, into account
    DFREF dfr = GetSupraPackageDFR()
    NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded

 
 
    WAVE/Z yWave = CsrWaveRef(A)
    if (!WaveExists(yWave))         // Cursor is not on any wave
        return -1
    endif
 
    WAVE/Z xWave = CsrXWaveRef(A)
    if (!WaveExists(xWave))         // Cursor is not on XY pair
        return -1
    endif
 
    Variable startX = hcsr(A)
    Variable endX = hcsr(B)
 
    if (startX > endX)
        return -1
    endif
 
    // To avoid accumulation of roundoff error we do this in two steps

 if (WaveExists(xWave))
        YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
        YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
    else
        YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
        YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
    endif

    gLastSliderValueAdded = sliderValue

 
    return 0
End



but somehow still it does not work ?
Try changing things this way ...

Function MoveSegment(SliderValue)
    Variable SliderValue
 
 // Take the previously-added slider value, if any, into account
    DFREF dfr = GetSupraPackageDFR()
    NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded
 
    WAVE/Z yWave = CsrWaveRef(A)
    if (!WaveExists(yWave))         // Cursor is not on any wave
        return -1
    endif
 
    WAVE/Z xWave = CsrXWaveRef(A)
//  this will exit the function when xWave does not exist
//  so no change will happen with scaled waves
// remove this segement of code
//  if (!WaveExists(xWave))         // Cursor is not on XY pair
//      return -1
//  endif
 
// this assures that start and end are arranged right regardless of cursors
    Variable startX = min(hcsr(A),hcsr(B))
    Variable endX = max(hcsr(B),hcsr(A))
 
// no longer needed here
//  if (startX > endX)                
//      return -1
//  endif
 
    // To avoid accumulation of roundoff error we do this in two steps
 
        if (WaveExists(xWave))
        YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
        YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
    else
        YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
        YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
    endif
 
    gLastSliderValueAdded = sliderValue

    return 0
End



--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thank you so much J. J. Weimer...worked perfectly ...Thanks a lot for your kind help.
How about changing final part of the code to

        if (WaveExists(xWave))
        YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
        YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
    else
        YWave(startX, endX) -=  gLastSliderValueAdded
        YWave(startX, endX) +=  sliderValue
    endif
 


The downside is that it employs a different syntax than the first part, but, at least for me, it's much easier to follow.

But maybe I miss something.
jtigor wrote:
How about changing final part of the code to ...


I agree with your coding, but I could also be missing something.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville