Setting Data Folder in Graph Macro

Hello All,

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.

Quote:

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:
Quote:
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
I made an Igor experiment with a data folder called "subfolder". The following works for me:
Macro mtest()

    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
Thank you for the advice to make it into a function Mr. Weeks. I was able to pretty much copy-paste the macros (I had three separate versions of the posted macro for different analyses) with only minor debugging.

Could you briefly explain the advantages and disadvantages of macros vs functions? It seems like functions are almost strictly better.

Thanks.
You get compile-time syntax checking in functions, whereas in macros only at run-time. One of the unappreciated consequences of this point is that macros only check the syntax of the code that actually runs, so it's very easy to have a syntax error in some branch that runs only rarely. Functions must be parsed completely at compile time, so the chances of this happening are much smaller.

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