KMPDUG ;OAK/RAK - CM Tools Graph Utility ;2/17/04 09:57
;;3.0;KMPD;;Jan 22, 2009;Build 42
;
EN(KMPUAR,KMPUTI,KMPUOPT,KMPUSTRT,KMPUTAR,KMPUXIT,KMPUMAX) ;entry point
;-----------------------------------------------------------------------
; KMPUAR.. Local or global array (passed by value) that contains graph
; information in the format:
;
; KMPUAR(...,0)=DataTitle^DataValue
; piece 1 - the title of the data
; piece 2 - the actual value of the data
;
; KMPUTI.. graph titles in 4 up-arrow pieces
; piece 1 - title of the graph
; piece 2 - second title of graph (if any)
; piece 3 - x axis title
; piece 4 - y axis title
;
; KMPUOPT. (optional) A string of one or more letters representing
; desired options.
; "A" - angle titles (only for vertical graph)
; "D" - double space
; "G" - print grid across graph
; "S" - display entries with MAX>9999 in scientific notation
; "V" - display 'vertical' graph
;
; KMPUSTRT (optional). Number to start graph.
; if KMPUSTRT=0 first hash mark of graph will equal 0
;
; KMPUTAR. (optional) Text array. Local or global array that
; contains text to be displayed with the graph.
;
; Example: KMPUTAR="UTIL($J,"
; KMPUTAR="^ASK(999999,23,10,"
; KMPUTAR="^TMP($J,""TEXT"","
;
; KMPUXIT. (optional) Exit without 'continue' text. This allows the
; programmer to use their own display for continuing
; 0 - do not exit - display 'continue' text
; 1 - exit
;
; KMPUMAX. (optional) Maximum scale - if not defined, the maximum value
; is determined from the data passed. If KMPUMAX is defined,
; scale will be adjusted accordingly.
;-----------------------------------------------------------------------
;
I '$D(KMPUAR) W !!?7,"...no array data...",!! D CONT Q
S KMPUSTRT=+$G(KMPUSTRT),KMPUOPT=$$UP^XLFSTR($G(KMPUOPT))
S KMPUXIT=+$G(KMPUXIT),KMPUMAX=+$G(KMPUMAX)
K:$G(KMPUTAR)="" KMPUTAR
I '$D(@KMPUAR) D Q
.W *7,!!?7,"...no information to graph...",!!
.D CONT
S DTIME=$S($D(DTIME):DTIME,1:600)
;
N BAR,BOTTOM,DATA,DEC,DEC1,DIV,DIVT,DNUM,DX,DY,END,GWIDTH,I,I1,LABEL,MAX
N MIN,NUM,OFFSET,SCALE,STEP,TEXT,TITLE,X,XCOORD,XTITLE,YNUM,YTITLE,Z
N IOBLC,IOBRC,IOBT,IOG1,IOG0,IOHL,IOLT,IOMT,IORT,IOTLC,IOTRC,IOTT,IOVL
N IOINHI,IOINLOW,IORVOFF,IORVON,IOUOFF,IOUON
;
D INIT^KMPDUG1 I KMPUOPT["D",(KMPUOPT'["V"),(YNUM>8) D Q
.W *7,!!?7,"...too many data elements to double space on a terminal"
.W !?7," for a Horizontal Graph..."
.W !!! D CONT
I KMPUOPT["D",(KMPUOPT["V"),(YNUM>34) D Q
.W *7,!!?7,"...too many data elements to double space on a terminal"
.W !?7," for a Vertical Graph..."
.W !!! D CONT
; if not a terminal do printer routine
I $E(IOST)'="C" Q ;D EN^KMPUGP Q
I $G(IOG1)']""!($G(IOG0)']"") D Q
.W *7,!!?7,"...unable to place terminal in graphics mode...",!!
.D CONT
I 'MAX D Q
.W *7,!!?7,"...unable to determine any data to graph or data all zeros...",!!
.D CONT
; if 'vertical' graph
I KMPUOPT["V" D EN^KMPDUGV Q
; draw graph - display titles - display data
D DRAW^KMPDUG1,TITLES^KMPDUG1,DATA
; if text to display.
I $D(KMPUTAR) D WP^KMPDU11(KMPUTAR,(BOTTOM+5),24) Q
D:'KMPUXIT CONT
Q
;
CONT ;-- hold screen
S DX=(IOM-23\2),DY=(IOSL-1) X IOXY
R "Press <RET> to continue",X:DTIME
Q
;
DATA ;-- display data in graph.
W IOG0 S DY=$S(KMPUOPT["D":1,1:2),BAR=0,I=""
F S I=$O(@KMPUAR@(I)) Q:I="" I $D(@KMPUAR@(I,0)) S DATA=@KMPUAR@(I,0) D
.S XCOORD=$P(DATA,U,2),END=(XCOORD-KMPUSTRT-STEP)
.S DX=16,DY=DY+$S(KMPUOPT["D":2,1:1)
.; if no data quit
.Q:$P(@KMPUAR@(I,0),U,2)']""
.F I1=0:STEP:END X IOXY W @BAR(BAR),! S DX=DX+1 Q:DX=68
.; print value in parenthesis
.S DX=69 X IOXY W "<",$J((XCOORD/DIV),$L($FN((MAX/DIV),"",DEC)),DEC),">"
.S BAR=$S(BAR=1:0,1:1)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPDUG 4076 printed Dec 13, 2024@01:41:05 Page 2
KMPDUG ;OAK/RAK - CM Tools Graph Utility ;2/17/04 09:57
+1 ;;3.0;KMPD;;Jan 22, 2009;Build 42
+2 ;
EN(KMPUAR,KMPUTI,KMPUOPT,KMPUSTRT,KMPUTAR,KMPUXIT,KMPUMAX) ;entry point
+1 ;-----------------------------------------------------------------------
+2 ; KMPUAR.. Local or global array (passed by value) that contains graph
+3 ; information in the format:
+4 ;
+5 ; KMPUAR(...,0)=DataTitle^DataValue
+6 ; piece 1 - the title of the data
+7 ; piece 2 - the actual value of the data
+8 ;
+9 ; KMPUTI.. graph titles in 4 up-arrow pieces
+10 ; piece 1 - title of the graph
+11 ; piece 2 - second title of graph (if any)
+12 ; piece 3 - x axis title
+13 ; piece 4 - y axis title
+14 ;
+15 ; KMPUOPT. (optional) A string of one or more letters representing
+16 ; desired options.
+17 ; "A" - angle titles (only for vertical graph)
+18 ; "D" - double space
+19 ; "G" - print grid across graph
+20 ; "S" - display entries with MAX>9999 in scientific notation
+21 ; "V" - display 'vertical' graph
+22 ;
+23 ; KMPUSTRT (optional). Number to start graph.
+24 ; if KMPUSTRT=0 first hash mark of graph will equal 0
+25 ;
+26 ; KMPUTAR. (optional) Text array. Local or global array that
+27 ; contains text to be displayed with the graph.
+28 ;
+29 ; Example: KMPUTAR="UTIL($J,"
+30 ; KMPUTAR="^ASK(999999,23,10,"
+31 ; KMPUTAR="^TMP($J,""TEXT"","
+32 ;
+33 ; KMPUXIT. (optional) Exit without 'continue' text. This allows the
+34 ; programmer to use their own display for continuing
+35 ; 0 - do not exit - display 'continue' text
+36 ; 1 - exit
+37 ;
+38 ; KMPUMAX. (optional) Maximum scale - if not defined, the maximum value
+39 ; is determined from the data passed. If KMPUMAX is defined,
+40 ; scale will be adjusted accordingly.
+41 ;-----------------------------------------------------------------------
+42 ;
+43 IF '$DATA(KMPUAR)
WRITE !!?7,"...no array data...",!!
DO CONT
QUIT
+44 SET KMPUSTRT=+$GET(KMPUSTRT)
SET KMPUOPT=$$UP^XLFSTR($GET(KMPUOPT))
+45 SET KMPUXIT=+$GET(KMPUXIT)
SET KMPUMAX=+$GET(KMPUMAX)
+46 if $GET(KMPUTAR)=""
KILL KMPUTAR
+47 IF '$DATA(@KMPUAR)
Begin DoDot:1
+48 WRITE *7,!!?7,"...no information to graph...",!!
+49 DO CONT
End DoDot:1
QUIT
+50 SET DTIME=$SELECT($DATA(DTIME):DTIME,1:600)
+51 ;
+52 NEW BAR,BOTTOM,DATA,DEC,DEC1,DIV,DIVT,DNUM,DX,DY,END,GWIDTH,I,I1,LABEL,MAX
+53 NEW MIN,NUM,OFFSET,SCALE,STEP,TEXT,TITLE,X,XCOORD,XTITLE,YNUM,YTITLE,Z
+54 NEW IOBLC,IOBRC,IOBT,IOG1,IOG0,IOHL,IOLT,IOMT,IORT,IOTLC,IOTRC,IOTT,IOVL
+55 NEW IOINHI,IOINLOW,IORVOFF,IORVON,IOUOFF,IOUON
+56 ;
+57 DO INIT^KMPDUG1
IF KMPUOPT["D"
IF (KMPUOPT'["V")
IF (YNUM>8)
Begin DoDot:1
+58 WRITE *7,!!?7,"...too many data elements to double space on a terminal"
+59 WRITE !?7," for a Horizontal Graph..."
+60 WRITE !!!
DO CONT
End DoDot:1
QUIT
+61 IF KMPUOPT["D"
IF (KMPUOPT["V")
IF (YNUM>34)
Begin DoDot:1
+62 WRITE *7,!!?7,"...too many data elements to double space on a terminal"
+63 WRITE !?7," for a Vertical Graph..."
+64 WRITE !!!
DO CONT
End DoDot:1
QUIT
+65 ; if not a terminal do printer routine
+66 ;D EN^KMPUGP Q
IF $EXTRACT(IOST)'="C"
QUIT
+67 IF $GET(IOG1)']""!($GET(IOG0)']"")
Begin DoDot:1
+68 WRITE *7,!!?7,"...unable to place terminal in graphics mode...",!!
+69 DO CONT
End DoDot:1
QUIT
+70 IF 'MAX
Begin DoDot:1
+71 WRITE *7,!!?7,"...unable to determine any data to graph or data all zeros...",!!
+72 DO CONT
End DoDot:1
QUIT
+73 ; if 'vertical' graph
+74 IF KMPUOPT["V"
DO EN^KMPDUGV
QUIT
+75 ; draw graph - display titles - display data
+76 DO DRAW^KMPDUG1
DO TITLES^KMPDUG1
DO DATA
+77 ; if text to display.
+78 IF $DATA(KMPUTAR)
DO WP^KMPDU11(KMPUTAR,(BOTTOM+5),24)
QUIT
+79 if 'KMPUXIT
DO CONT
+80 QUIT
+81 ;
CONT ;-- hold screen
+1 SET DX=(IOM-23\2)
SET DY=(IOSL-1)
XECUTE IOXY
+2 READ "Press <RET> to continue",X:DTIME
+3 QUIT
+4 ;
DATA ;-- display data in graph.
+1 WRITE IOG0
SET DY=$SELECT(KMPUOPT["D":1,1:2)
SET BAR=0
SET I=""
+2 FOR
SET I=$ORDER(@KMPUAR@(I))
if I=""
QUIT
IF $DATA(@KMPUAR@(I,0))
SET DATA=@KMPUAR@(I,0)
Begin DoDot:1
+3 SET XCOORD=$PIECE(DATA,U,2)
SET END=(XCOORD-KMPUSTRT-STEP)
+4 SET DX=16
SET DY=DY+$SELECT(KMPUOPT["D":2,1:1)
+5 ; if no data quit
+6 if $PIECE(@KMPUAR@(I,0),U,2)']""
QUIT
+7 FOR I1=0:STEP:END
XECUTE IOXY
WRITE @BAR(BAR),!
SET DX=DX+1
if DX=68
QUIT
+8 ; print value in parenthesis
+9 SET DX=69
XECUTE IOXY
WRITE "<",$JUSTIFY((XCOORD/DIV),$LENGTH($FNUMBER((MAX/DIV),"",DEC)),DEC),">"
+10 SET BAR=$SELECT(BAR=1:0,1:1)
End DoDot:1
+11 QUIT