Setting Data Folder in Graph Macro
poor_grad_student
I am trying to facilitate my data analysis. My data is structured as such: root:SampleA:Trial1:"data here"
What I am trying to do is quickly analyze the data from several samples and trials. Below I have pasted the graph macro which is basically what I want to do. The only comment in the code is my question: How do I make the folder from which the data is analyzed a dynamic variable, rather than static.
Window passive_cycle_comparison() : //Graph
PauseUpdate; Silent 1 // building window...
String fldrSav0= GetDataFolder(1)
SetDataFolder root:MuscleB:sine1 // How do I make this line dynamic, rather than a static folder
string my_folder=GetDataFolder(1)
string display_text= "Data from: " + " " +my_folder
Display /W=(35.25,42.5,798,555.5) first_cycle_force, fifth_cycle_force, seventh_cycle_force
SetDataFolder fldrSav0
ModifyGraph rgb(fifth_cycle_force)=(0,52224,26368),rgb(seventh_cycle_force)=(16384,16384,65280)
Label left "Force (N)"
Label bottom "Phase (-1:1)"
Legend/C/N=text0/J/A=MC/X=36.96/Y=36.70 "\\s(first_cycle_force) first_passive\r\\s(fifth_cycle_force) fifth_cycle_2nd passive"
AppendText "\\s(seventh_cycle_force) seventh_cycle_3rd_passive"
TextBox/C/N=text1/A=MC/X=-1.95/Y=47.31 "\\Z18Passive cycle comparison"
TextBox/C/N=text1/A=MC/X=13.00/Y=43.53 display_text
EndMacro
I have tried doing something like the following:
string desired_folder
prompt desired_folder, "Enter full path of desired data folder"
DoPrompt "Enter Data Path", desired_folder
SetDataFolder $(desired_folder)
I know the above method works in different circumstances but apparently not in (graph) macros.
Alternatively, if I cannot use a prompt, is there a way to at least make the graph macro not back-out to the root: folder upon initiation of the macro? If I could just (manually) choose the right data folder before initiating the graphs that would work. Unfortunately it appears that the initial declaration of the graph macro sets the data folder to root:.
Thanks,
poor_grad_student
String df = "root:subfolder"
SetDataFolder $df
end
It makes me feel all shaky all over to post a Macro... really you should write the code as a function.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 10, 2015 at 09:50 am - Permalink
Could you briefly explain the advantages and disadvantages of macros vs functions? It seems like functions are almost strictly better.
Thanks.
April 10, 2015 at 10:44 am - Permalink
They execute *much* faster.
New programming constructs go into functions, and rarely into macros. So, for instance, you can write for loops in functions and not in macros.
The main difficulty with functions is the need for Wave, NVAR and SVAR statements. They serve two purposes: at compile time they simply tell Igor's compiler what kind of object a given name refers to so that it can compile the right kind of code. At run-time, they actually cause Igor to look up the real object and connect it to the reference created by the compiler when it compiled the name.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 10, 2015 at 12:18 pm - Permalink