Having just discovered MUMPS, I in the process of familiarising
myself with the M language and am having a little problem how to do
something.
I have defined the following global
GTM>do ^%G
Output device: <terminal>:
List ^
GTM>do ^%G
Output device: <terminal>:
List ^CADD
^CADD(1,3)="1 Pond Walk~Chester~CH1 4XX"
^CADD(1,7)="2 Pond Walk~Chester~CH1 4XX"
^CADD(1,11)="8 Pond Walk~Chester~CH1 4XX"
^CADD(1,12)="22 Pond Walk~Chester~CH1 4XX"
^CADD(1,14)="122 Pond Walk~Chester~CH1 4XX"
^CADD(1,15)="122b Pond Walk~Chester~CH1 4XX"
^CADD(1,105)="1 Apple Rd~Chester~CH1 4XX"
^CADD(1,106)="2 Apple Rd~Chester~CH1 4XX"
^CADD(1,116)="22 Apple Rd~Chester~CH1 4XX"
List ^
GTM>
If I was looking to display 3 records from the 4th record e.g.
^CADD(1,12)="22 Pond Walk~Chester~CH1 4XX"
^CADD(1,14)="122 Pond Walk~Chester~CH1 4XX"
^CADD(1,15)="122b Pond Walk~Chester~CH1 4XX"
How would I do this in an M program, I know I could use the order
function to loop through the global with a counter and at the 4th
record start to display the record. But think this would not be a
good idea if there there say 100,000 records and I needed to display
20 records starting from the 50993 for example
I would be happy to hear any advise you can offer.
Thanks Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is a simple MUMPS command line solution that assumes
1) your example starting value is a defined record number
2) all records in your structure have simple values,
i.e. ($d(^CADD(1,n))#2=1) for all n
set n=50993
for count=1:1:20 write ^CADD(1,n),! set n=$o(^(n)) quit:n=""
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The GT.M Programmers Guide (go to http://fis-gtm.com then click on the User Documentation tab from where you will be able to access the latest user documentation) is easy to read and those who are expert at programming other languages can probably pick up GT.M from it.
My recommended MUMPS book is Prof. Richard Walters' "M Programming: A Comprehensive Guide".
Regards
-- Bhaskar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As you state it you assumed that
~ 1) [Richard's] example starting value is a defined record number
~ 2) all records in your structure have simple values,
~ i.e. ($d(^CADD(1,n))#2=1) for all n
My answer in comp.languages.mumps was wrong, I mixed $Get and
$Query; I found a solution to Richard's original question with:
GTM>zwr CAD
CAD(1,1)=123
CAD(1,2)=789
CAD(1,4)=98987
CAD(1,5)=8909
CAD(1,6)=32098342
CAD(1,7)=32098
CAD(1,9)=3098
GTM>s y="mlkj"
GTM>f i=2:1:7 s x=$Q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x! s y=x
CAD(1,2)=789
CAD(1,4)=98987
CAD(1,5)=8909
CAD(1,6)=32098342
CAD(1,7)=32098
Isn't it a nicer solution ? And how would you deal with ($d(CAD(1,n))#2'<1),
for example to also display CAD(1,5,1)=876 if we had the series
...
CAD(1,5)=8909
CAD(1,5,1)=876
CAD(1,6)=32098342
... ??
Thanks.
Seb
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Seb,
If my solution is adapted to your array "CAD" (replacing "^CADD"), then my 2nd assumption already covers your example:
...
CAD(1,5)=8909
CAD(1,5,1)=876
CAD(1,6)=32098342
...
$d(CAD(1,5))=11 and 11#2=1
The node CAD(1,5,1) would be ignored.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GTM>f i=2:1:7 s x=$q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x,! s y=x
CAD(1,2)=789
CAD(1,4)=239834
CAD(1,5)=46
CAD(1,5,1)=238734
CAD(1,7)=32
And I WANT CAD(1,6) to be displayed, as I've asked i to loop from 2
through 7 in CAD(1,i): how should one amend my line
~ f i=2:1:7 s x=$q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x,! s y=x
in order to not miss CAD(1,6) ??
Thanks...
Regards,
Sébastien
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for Your advice for $ZCMdline.
It was described in documentation and the previous posts.
I posted this code with the aim to show that the GT.M offers different variants for the solving of the problem and developer have a box of possibilities.
We had the great dates this week - the Elders days(days of memory of the dead natives), the MayWood and and I want to send You a greetings
and the best wishes to You and the best future of Your excellent product. The PIPE You did in GT.M V5.3 is really cool thing!
It is makes the possible to do more useful tools (I hope to offer something of service tools with the PIPE in June).
With the greetings from Ukraine, A.V.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
Having just discovered MUMPS, I in the process of familiarising
myself with the M language and am having a little problem how to do
something.
I have defined the following global
GTM>do ^%G
Output device: <terminal>:
List ^
GTM>do ^%G
Output device: <terminal>:
List ^CADD
^CADD(1,3)="1 Pond Walk~Chester~CH1 4XX"
^CADD(1,7)="2 Pond Walk~Chester~CH1 4XX"
^CADD(1,11)="8 Pond Walk~Chester~CH1 4XX"
^CADD(1,12)="22 Pond Walk~Chester~CH1 4XX"
^CADD(1,14)="122 Pond Walk~Chester~CH1 4XX"
^CADD(1,15)="122b Pond Walk~Chester~CH1 4XX"
^CADD(1,105)="1 Apple Rd~Chester~CH1 4XX"
^CADD(1,106)="2 Apple Rd~Chester~CH1 4XX"
^CADD(1,116)="22 Apple Rd~Chester~CH1 4XX"
List ^
GTM>
If I was looking to display 3 records from the 4th record e.g.
^CADD(1,12)="22 Pond Walk~Chester~CH1 4XX"
^CADD(1,14)="122 Pond Walk~Chester~CH1 4XX"
^CADD(1,15)="122b Pond Walk~Chester~CH1 4XX"
How would I do this in an M program, I know I could use the order
function to loop through the global with a counter and at the 4th
record start to display the record. But think this would not be a
good idea if there there say 100,000 records and I needed to display
20 records starting from the 50993 for example
I would be happy to hear any advise you can offer.
Thanks Richard.
Richard --
Look at the ZWRITE command. For example ZWRITE ^CADD(1,12:15) would display nodes with a second subscript from 12 through 15.
Regards
-- Bhaskar
Here is a simple MUMPS command line solution that assumes
1) your example starting value is a defined record number
2) all records in your structure have simple values,
i.e. ($d(^CADD(1,n))#2=1) for all n
set n=50993
for count=1:1:20 write ^CADD(1,n),! set n=$o(^(n)) quit:n=""
Thank you Bhaskar & James,
A faultless reply, thanks for the quick response.
Another question if a may :)
Is it also possible to read parameters from the command line and pass them into a M routine for example
$mumps -run ^%getcadd 12 15
12 being the starting node and 15 being the ending node or would I wrap it in a shell script for example.
Getcad < EOF
mumps -run ^%getcadd
12
15
EOF
and use the input function within M to capture the values.
Thanks Agian
Richard.
PS Think I need to buy a mumps book :)
Yes, the GT.M programmer manual has an example very similar to yours.
The special variable $ZCmdLine will return the command line tail.
Sure. By way of example, here is a GT.M way to do the equivalent of awk -F"." '{print $1}' <temp.tmp:
$ cat xcmd.m
xcmd Xecute $ZCMdline Quit
$ cat temp.tmp
1.0
2
.3
4.5.6
$ mumps -run xcmd 'Use $Principal:Exception="Halt" For Read x Write $Piece(x,".",1),!' <temp.tmp
1
2
4
$
The GT.M Programmers Guide (go to http://fis-gtm.com then click on the User Documentation tab from where you will be able to access the latest user documentation) is easy to read and those who are expert at programming other languages can probably pick up GT.M from it.
My recommended MUMPS book is Prof. Richard Walters' "M Programming: A Comprehensive Guide".
Regards
-- Bhaskar
Jim,
As you state it you assumed that
~ 1) [Richard's] example starting value is a defined record number
~ 2) all records in your structure have simple values,
~ i.e. ($d(^CADD(1,n))#2=1) for all n
My answer in comp.languages.mumps was wrong, I mixed $Get and
$Query; I found a solution to Richard's original question with:
GTM>zwr CAD
CAD(1,1)=123
CAD(1,2)=789
CAD(1,4)=98987
CAD(1,5)=8909
CAD(1,6)=32098342
CAD(1,7)=32098
CAD(1,9)=3098
GTM>s y="mlkj"
GTM>f i=2:1:7 s x=$Q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x! s y=x
CAD(1,2)=789
CAD(1,4)=98987
CAD(1,5)=8909
CAD(1,6)=32098342
CAD(1,7)=32098
Isn't it a nicer solution ? And how would you deal with ($d(CAD(1,n))#2'<1),
for example to also display CAD(1,5,1)=876 if we had the series
...
CAD(1,5)=8909
CAD(1,5,1)=876
CAD(1,6)=32098342
... ??
Thanks.
Seb
Seb,
If my solution is adapted to your array "CAD" (replacing "^CADD"), then my 2nd assumption already covers your example:
...
CAD(1,5)=8909
CAD(1,5,1)=876
CAD(1,6)=32098342
...
$d(CAD(1,5))=11 and 11#2=1
The node CAD(1,5,1) would be ignored.
Woops ! I meant "isn't *there* a nicer solution" of course...
Sorry.
Jim,
In fact I tested it too quickly and something escaped me: my line
processes CAD(1,5) subnode CAD(1,5,1) and displays it, but then
skips CAD(1,6):
GTM>zwr CAD
CAD(1,1)=9
CAD(1,2)=789
CAD(1,4)=239834
CAD(1,5)=46
CAD(1,5,1)=238734
CAD(1,6)=334
CAD(1,7)=32
CAD(1,9)=34
GTM>f i=2:1:7 s x=$q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x,! s y=x
CAD(1,2)=789
CAD(1,4)=239834
CAD(1,5)=46
CAD(1,5,1)=238734
CAD(1,7)=32
And I WANT CAD(1,6) to be displayed, as I've asked i to loop from 2
through 7 in CAD(1,i): how should one amend my line
~ f i=2:1:7 s x=$q(CAD(1,i-1)) if (x'="")&(x'=y) w x,"=",@x,! s y=x
in order to not miss CAD(1,6) ??
Thanks...
Regards,
Sébastien
To pass parameters from the shell You could use the next variant:
In shell
export incom="12 15"
gtm --run ^routine
Your routine:
routine ;receive parameters from shell
set incom=$ztrlnm("incom")
for i=1:1:$length(incom," ") s incom(i)=$p(incom," ",i)
.... further code .....
For access to the command line, check out the $ZCMdline intrinsic special variable.
Regards
-- Bhaskar
Thanks for Your advice for $ZCMdline.
It was described in documentation and the previous posts.
I posted this code with the aim to show that the GT.M offers different variants for the solving of the problem and developer have a box of possibilities.
We had the great dates this week - the Elders days(days of memory of the dead natives), the MayWood and and I want to send You a greetings
and the best wishes to You and the best future of Your excellent product. The PIPE You did in GT.M V5.3 is really cool thing!
It is makes the possible to do more useful tools (I hope to offer something of service tools with the PIPE in June).
With the greetings from Ukraine, A.V.
To K.S.Bhaskar:
I thought about something like this
$ cat xcmd.m
xcmd Xecute $ZCMdline Quit
$ mumps -run xcmd '....evil commands....'
What do You recommend for such case?