FUNCTION calcent
*
* Use this function to center text on screen, or the printed page.
* This function requires that the size of the page (columns) and 
* the string be passed to it.
*
parameters size,title
titlelen=len(trim(title))
titlecol=(size/2)-(titlelen/2)
return(titlecol)

FUNCTION time_cnv
*
* Use this function to convert time entered by the user to numbers so
* that amount of time elapsed can be calulated.  
*
* Times are entered in the format HH:MM X 
* 	where  HH=hours
*	       MM=minutes
*	 	X= either A or P for am/pm
* 
* This way the user can enter time in 12 hour format (1:00 P instead of
*     13:00)
parameters hrs,mins,ses
hours=val(hrs)
minutes=val(mins)
if (hours < 12) .and. ses='P'
	hours=hours+12 
endif
if (hours=12) .and. ses='A'
	hours=0
endif
time=(hours*3600)+(minutes*60)
return(time)


FUNCTION etime
*
* This will calculate the amount of elapsed time between two events.  It uses
* the results of TIME_CNV (above) to get its result.  Output is in the form
*			HH:MM
*
parameters time1,time2
store '  ' to hrs,mins
tottime=time2-time1
hours=int((tottime/3600))
minutes=mod(tottime,3600)/60
if hours < 10
	if hours > 0
		hrs='0'+str(hours,1,0)
	else
		hrs='00'
	endif
else
	hrs=str(hours,2,0)
endif
if minutes < 10
	if minutes > 0
		mins='0'+str(minutes,1,0)
	else
		mins='00'
	endif
else
	mins=str(minutes,2,0)
endif
etime=hrs+':'+mins
return(etime)


FUNCTION TimeStr
*
* This will convert the ouput of ETIME into real language.  For example
*  00:14 will be ouput as   "14 Minute(s)"
*
parameters time
*
if substr(time,1,2)='00'
	hrs=' '
else
	if substr(time,1,1)='0'
		hrs=substr(time,2,1)
	else
		hrs=substr(time,1,2)
	endif
endif
if substr(time,4,2)='00'
	mins=' '
else
	if substr(time,4,1)='0'
		mins=substr(time,5,1)
	else
		mins=substr(time,4,2)
	endif
endif
if hrs <> ' '
	hrstr=hrs+' Hour(s) '
else
	hrstr=''
endif
if mins <> ' '
	minstr=mins+' Minute(s) '
else
	minstr=''
endif
string=hrstr+minstr
return (string)


FUNCTION box
* Program to draw a pseudo-3D box on screen with the screen title.
* The title, however, must be less than 69 characters in length.
* Otherwise, the box will not fit on the screen.
*
* When you use this function, use the ?? statement to output it since it
* defaults to print at the top of the screen.
*
parameters banner
clear
row=1
*
* Get length of header
*
headlen=len(trim(banner))
if mod(headlen,2) <> 0
    headlen=headlen+1    && Check for odd length.  Add 1 to make even.
endif
*
* Calculate columns to place data, and length of box.
*
headcol=40-(headlen/2)   && Column to start banner
boxcol=headcol-4         && Left edge of box
boxlen=headlen+8         && Width of box
set color to w+/r
*
* Draw box
*
do while row < 4
    @row,boxcol clear to row,(boxcol+boxlen)
    row=row+1
enddo
set color to n/b
@0,boxcol+1 say repli(chr(220),boxlen+1)
@1,(boxcol+boxlen+1) say chr(219)
@2,(boxcol+boxlen+1) say chr(219)
@3,(boxcol+boxlen+1) say chr(223)
set color to w+/r
@2,headcol say banner
set color to w+/b
return ""
..-.... 1200  N81N          ....................