Load User Procedures from Menu

Hi,

I have a very simple question to ask.

I have a bunch of self-written procedures saved in User Procedures folder. I don't want to use them as global procedures as they are slowing down initialization/startup of Igor and also not all of them are required for a single experiment.

Instead, I am having a global procedures (saved in Igor Procedures folder) which will create a new Menu containing items which should load corresponding procedures from User Procedures folder.

I have tried the following two methods but none of them are working.

Method 1:

 

Menu  "My Procedures"
"Procedure 1", loadproc(1)
"Procedure 2", loadproc(2)
End

Function loadproc()
Variable indx
if(indx==1)
#include "Procedure 1"
elseif(indx==2)
#include "Procedure 2"
endif

 


Method 2:

Menu  "My Procedures"
"Procedure 1", #include "Procedure 1"
"Procedure 2", #include "Procedure 2"
End

From the manual, what I understand is #include will only work before starting any function in a procedure and also found working in such a way.

 

Can someone help me out how to solve this problem?

 

Thanks a lot in advance.

SS

There are various solutions to this. Procedure loader is a good one and it is "done" for you.

Most basic is to use your method 2 but call a function (in the same procedure file) which has

        Execute/P "INSERTINCLUDE \"YourFileWithIncludes\""
        Execute/P "COMPILEPROCEDURES "

of a file "YourFileWithIncludes.ipf" located in User Procedures. This YourFileWithIncludes.ipf contains rest of #include lines you need. 

 

Already tried before posting, but Procedure Loader did not worked for me as I am using an older version (6).

However, the solution provided by ilavsky worked for me.

 

Thanks again  :-)

SS

The problem with your solution is that any command that starts with pound sign ("#") is a compiler directive, not a run-time command. As noted by @ilavsky, the solution is the Execute/P command, which has the power to add compiler directives to the main procedure window, and then trigger a compile.