How to call a Macro inside a function

Here is a Macro that I wrote. Inside this Macro,  It calls another macro named loadODMRtrace. But I would like to change this Macro into a Function, so that I could type the function in the commend window to load traces. I am wondering if there is anyway to modify this code, so that I could have a Function loadODMRtraces(pathname), and call the Macro loadODMRtrace inside the function. See the details of coding below. Much appreciated!

Macro loadODMRtraces(pathname)	
	// calls loadtrace on all files in folder called pathname
	// Load and process all files in a given folder.
	//   The folder is specified by pathName which becomes a dialog	
	//   if no input is given.
	//   YOU MUST INCLUDE #include <Strings as Lists>
	//   SOMEWHERE IN YOUR PROCEDURE, AS THIS MACRO
	//   CALLS SUBROUTINES FROM THAT INCLUDE FILE.
	String pathName	//  name of symbolic path or "" to get dialog
	variable/d numfiles
	String filename
	PauseUpdate; Silent 1	// Processing files . . . 
	Variable index=0
	variable/d tracenum
	if (strlen(pathName)==0)			// if no path specified, create one
		NewPath/O temporaryPath		// this will put up a dialog
		pathName = "temporaryPath"
	endif
	print IndexedFile($pathName,-1,"????")
	do
		fileName = IndexedFile($pathName, index, ".csv")
		if (strlen(fileName)==0)
			break // break out of loop
		endif
//		Assume file name is of form mmddyyc.xxxx, where x is a number. Strip off the number.
		tracenum = str2num(filename[7,10])
		loadODMRtrace(tracenum,filename,pathname)
		print index,filename,tracenum
		index += 1
	while(1)
	if (Exists("temporaryPath"))			// kill temp path if it exists
		KillPath temporaryPath
	endif
EndMacro

 

Macros are ancient and should be avoided in most circumstances. Use functions instead.

In the case of the macro above, to convert it to a function, all you need to do is change "Macro" to "Function" and remove the PauseUpdate line. You don't have to but I would change "EndMacro" to "End".

If you do this, you will also need to change the loadODMRtrace subroutine to a function.

For further discussion, execute this:

DisplayHelpTopic "Converting Macros To Functions"