Setting a Data Folder Path in a user-defined function
N.Duc
I am trying to use the SetDataFolder command in a userdefined function, so that I may get to the waves I create with it from other functions.
However, I get the following error message :
Function RelativeKayserCalc(Rel,X0)
SetDataFolder root:Data:Load
Variable Rel,Xpnts,i=0
wave X0
wave XK
Xpnts = numpnts(X0)
do
XK[i]=CalcStokes(X0[i],Rel)
i=i+1
while(i<Xpnts)
End
SetDataFolder root:Data:Load
Variable Rel,Xpnts,i=0
wave X0
wave XK
Xpnts = numpnts(X0)
do
XK[i]=CalcStokes(X0[i],Rel)
i=i+1
while(i<Xpnts)
End
This function runs after being called by a top level routine that creates the new data folder paths.
Is there a way around this problem?
I have the impression there should be an easy solution, but I've tried to no avail.
Thanks,
Nicolas
June 27, 2013 at 03:14 am - Permalink
Variable Rel // first, always declare your input
Wave X0
Variable i // keep in-func declarations separate
Wave workwave = root:Data:Load:XK // reference the wave directly without setdatafolder
for (i = 0; i < numpnts(X0); i+=1) // I would use a for loop here, but that's just my taste
workwave[i]=CalcStokes(X0[i],Rel)
endfor
End
June 27, 2013 at 06:13 am - Permalink
Thanks a lot for helping me out.
I had a feeling it was going to be an easy answer :).
I still have a little work ahead of me!
Nicolas
June 27, 2013 at 06:27 am - Permalink
variable Rel
wave X0
DFREF mydatafolder = root:Data:Load
wave/SDFR=mydatafolder workwave = XK
workwave=CalcStokes(X0[p],Rel)
end
For this specific short case, I would just eliminate the call to RelativeKayserCalc(...) in the main function and replace it directly by its code. You may have other things going on in the entire function though that make sense for it to be a full function.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
June 27, 2013 at 10:14 am - Permalink
Variable Rel
Wave X0
DFREF dfr = root:Data:Load
Wave XK = dfr:XK
XK=CalcStokes(X0[p],Rel)
End
The /SDFR flag is supported only in WAVE, NVAR and SVAR statements.
The dfr: syntax shown above is supported wherever Igor expects a wave or global variable. This includes WAVE, NVAR and SVAR statements and in any command that uses a wave, for example, in a Display command.
Often dfr will be passed as a parameter to identify the data folder in which the function is to work.
June 27, 2013 at 11:29 am - Permalink
Ah yes ... that is cleaner for sure.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
June 27, 2013 at 02:01 pm - Permalink