Wednesday, April 2, 2008

Create a new routine on GT.M

The way to write programmatic functionality against storage in a GT.M database is to implement routines. For this purpose I've created a folder '/gtm/rou' to accommodate new routines.
For convenience I've opened up access to create routines at this location.


user@machine:~$ sudo chmod 777 /gtm/rou

user@machine:~$ ls -l /gtm
total 12
drwxr-xr-x 3 root root 4096 2008-04-01 21:13 dist
drwxr-xr-x 2 root root 4096 2008-04-02 06:09 gbl
drwxrwxrwx 2 root root 4096 2008-03-30 21:52 rou


The editor environment variable was previously defined in the user profile.



user@machine:~$ printenv | grep -e EDITOR
EDITOR=/usr/bin/vim

The mumps prompt is started with the 'gtm' alias defined in an earlier post.



user@machine:~$ gtm

GTM>


The utility ZEDIT is invoked on the mumps prompt with a quoted string containing the path to a mumps routine you wish to edit.



GTM>ZEDIT "/gtm/rou/testroutine"


Note that the full path was specified. By default the editor will use the $gtm_dist location. It would seem that this is because the program mumps is located in $gtm_dist directory.
Using VIM the following routine test routine was entered



testroutine
Write !,"hello world from testroutine"
Quit
T1
Write !,"At line label T1^testroutine"
Quit

After saving the routine one quits the mumps prompt with the Halt command.

It is also OK to create the routine outside of the mumps command line, for example with gedit:



user@machine:~$ gedit /gtm/rou/testroutine.m


Note that we have to specify the file type '.m' in the path syntax.


If the routine is run interactively from the mumps prompt and it has not yet been compiled (or has been edited), the environment compiles the routine before running it. If the routine is already compiled (from a previous run) then the mumps environment runs the compiled version straight away.
The routine can be started by the 'Do Linelabel' syntax at the mumps prompt.
For example:


user@machine:~$ gtm

GTM>D ^testroutine

This is the test routine
GTM>Do T1^testroutine

This is line label T1 of testroutine
GTM>halt
user@machine:~$

No comments: