Using waves from a folder in a function running in root

Hi, 

I request advice on the following situation: 

I have a folder "X" (address is root:X) that contains a set of waves. 

Now I have a function running in the root: that needs to use the waves contained in folder X. 

I think this isn't a complex problem but I couldn't get hold of the syntax.. 

I am calling the waves in the function using WAVE, hoping this would turn them global and thus would run within the function. However, it doesn't work. The function returns error saying it's trying to operate on a missing wave. 

Kindly advise how I could make a function that is running in root: use waves that are located in a folder. 

 

Many thanks, 

Peeyush  

Oops I think I just figured it out. Here is what I did: 

 

setdatafolder root:X

WAVE  wave1,wave2,wave3....

setdatafolder root: 

Function()

....

end 

 

In case if someone knows a more efficient way, kindly let me know. My problem was that I was not setting the data folder to X before calling WAVE. 

It's better to use the /SDFR flag with wave, rather than changing the data folder.

DisplayHelpTopic "The /SDFR Flag"

In general, if you can avoid changing data folder within a function that's for the best. If your code exits unexpectedly, or you don't take account of some pathway in your code that doesn't reset the data folder, you will leave the user in an unexpected data folder, which is confusing and will likely break your code.

What you did should work fine, though.

 

An example showing Tony's suggestion.  If the folder containing your waves is "root:MyFolder" which contains wTest and wTest2 waves -- 

Function fDFRtest()
    DFREF dfWorkDir = root:MyFolder
    WAVE/SDFR=dfWorkDir wTest, wTest2
    wTest = p^2
    wTest2 = p
    print wTest , wTest2
End

 

Wow the DFREF /SDFR syntax worked swimmingly well! Thanks a lot, guys. I was being driven to the brink of insanity sorting the overpopulated root folder since my experiment/program is over 600 MBs in size and more than 10,000 lines of code. Learned something very new today with the DFREF /SDFR. I greatly appreciate the help and advice!