PillarSoft

http://www.pillarsoft.net/os-2-software/rexx/apmt-example-includes-undocumented-function-interm.shtml

APMT example, includes undocumented function (Intermediate level)

Contributed by: Doug Rickman, Global Hydrology and Climate Center, MSFC, NASA

This is aimed at intermediate REXX users.

APMT is very useful for testing and control of existing PM programs. This example shows how to control PMView. The task is to read in a large image, reduce its size recursively and then save the result to a new file.


 


/* */
signal on Halt
signal on NotReady

if rxfuncquery('rexxlibregister') then do         /* this will start rexxlib */
    call rxfuncadd 'rexxlibregister', 'rexxlib', 'rexxlibregister' 
    call rexxlibregister
    end
if rxfuncquery('sysloadfuncs') then do           /* this will start rexxutil */
    CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
    CALL SysLoadFuncs
    end

parse arg in
in=strip(in)
parse value parsefn(in) with drive path filename extension
out=Drive':'path||filename'_reduced.'||extension2
backup=in||'backup'
if in='' | in='?' | in='-?' | in='/?' then call Help
if dosisfile(in)<>1 then do
   say 'The input file: ' in' is not a valid file.'
    exit
    end /* do */

rc=dosdel(backup)
rc=doscopy(in,backup)

address cmd 'start G:\GRAPHICS\PMVIEW\PMVIEW.EXE' in


call apmt_init

say 'Loading image...'
rc=Wait("5000")

/* Get the PMView Window */
rc = SELECT_WINDOW(filename'.'extension)
if rc=4 then call ErrorCode Select_Window 4
rc = QUERY_TITLE("title")
say "The selected window's title is " title

/* Get the File:Recall list and recall first item. */
rc =  MENU_QUERY_ALL("~File","Recall","Options2")
   if rc = 0 then do i = 1 to options2.0
   /* say 'Option choice 'i 'is :'options2.i */
   end
rc=Menu_Select('File','Recall',Options2.1)

say 'Now displaying the image.'
rc=Wait("3000")

do 5
   call ReduceSize
   end

rc=Menu_Select('File','Save')
rc=Menu_Select('File','Exit')

rc = END_SESSION()
return 1


APMT_INIT:
signal on error name  errorexit
call rxfuncadd  'APMTLoadFuncs',  'apmtext', 'APMTLoadFuncs'
call APMTLoadFuncs;
rc = INIT_SESSION();
if rc \= 0
   then do
     say apmtmsg
     say "I'm dead."
     exit
     end
signal on halt name APMT_CLOSE
return

/* --------------------------------------------------------------------------*/
/* --- begin subroutine - Help:                                 -------------*/
Help:
rc= charout(,'1b'x||'[31;7m'||'Program Name:'||'1b'x||'[0m'||'0d0a'x)
say 'General purpose'

say ''
rc= charout(,'1b'x||'[33;1m'||'usage:'||'1b'x||'[0m')
say ' Program name, arg1 arg2 ....'
say ''

rc= charout(,'1b'x||'[33;1m'||'where:'||'1b'x||'[0m')
say ' arg1 = explaination'
say ''

rc= charout(,'1b'x||'[33;1m'||'Exam: '||'1b'x||'[0m')
say ' Program name arg1 arg2 '
say ''

rc= charout(,'1b'x||'[33;1m'||'notes:'||'1b'x||'[0m')
say ' Notes about program function'
say ''

say ''
say 'Doug Rickman  ,1998'
exit
return

/* --- end  subroutine - Help:                                  -------------*/
/* --------------------------------------------------------------------------*/

/* --------------------------------------------------------------------------*/
/* --- begin subroutine - Halt:                                 -------------*/
Halt:
say 'This is a graceful exit from a Cntl-C'
exit
/* --- end  subroutine - Halt:                                  -------------*/
/* --------------------------------------------------------------------------*/
/* --- begin subroutine - NotReady:                             -------------*/
NotReady:
say 'It would seem that you are pointing at non-existant data.  Oops.  Bye!'
exit
/* --- end  subroutine - NotReady:                              -------------*/
/* --------------------------------------------------------------------------*/

/* --------------------------------------------------------------------------*/
/* --- begin subroutine - ReduceSize:                           -------------*/
ReduceSize:
/* Reduce file size. */
/* Get the current window's title. */
rc = QUERY_TITLE("Title")

/* Get the Transform:Size dialog. */
rc=Menu_Select('Transform','Size')
rc=Wait("500")
rc = SELECT_DialogWINDOW("*")
do 14
   rc = SPINBUTTON_SPINDOWN("1")
   end
rc=Wait("2000")

rc=PushButton_Click('OK','1')
say 'rc='rc
rc=Wait("6000")

/*Restore selection to the main window. */
rc = SELECT_WINDOW(Title)

return 1
/* --- end  subroutine - ReduceSize:                            -------------*/
/* --------------------------------------------------------------------------*/


ErrorCode:
procedure
parse arg source codenumber

select
   when codenumber=4 then do
      say '"Error doing 'source'"'
      say 'Unable to find the object specified.'
      end
   otherwise say "A new error.  Will wonders never cease!"
   end  /* select */

exit
end

/* Code fragements */
/* To find the titles for the first 10 windows and list to screen. */
do i=1 to 10
   rc = SELECT_WINDOW("*",,i)
   rc = QUERY_TITLE("title")
   say "The selected window's title is " title
   end /* do */


/* Look at the text of the first SPINBUTTON      */
rc = SPINBUTTON_QUERY_TEXT("1", "txt")
say 'rc='rc
say 'txt =' txt

/* How many checkboxes?                          */
rc = CHECKBOX_QUERY_ALL( "cbox")
say "number of checkboxes: " cbox.0
do i = 1 to cbox.0
   say 'checkbox  no 'i 'is: 'cbox.i
   end
 
/* How many pushbuttons?                          */
rc = PUSHBUTTON_QUERY_ALL( "buttons")
say "number of pushbuttons: " buttons.0
do i = 1 to buttons.0
   say 'button no 'i 'is: 'buttons.i
   end

/* How many radiobuttons?  Note this is not documented!!!! */
rc = SPINBUTTON_HOW_MANY("button")
say "number of spinbuttons: " button