Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-05 - 43,50337/23/puttim.sim
There is 1 other file named puttim.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-A/-I/-D);
EXTERNAL TEXT PROCEDURE putfloat;
TEXT PROCEDURE puttime(field,time,unit,secdec);
TEXT field;   REAL time;
CHARACTER unit;   INTEGER secdec;
!
Puttime edits a REAL variable representing a TIME value
left justified into the text fIELD in
seconds	if UNIT = 'S'
minutes	if UNIT = 'M'
hours	if UNIT = 'H'
days	if UNIT = 'D'
Else Putreal editing will be used.
The FIELD must have a minimum length of
12	if secdec < 0
15	if secdec = 0
16+secdec	if secdec > 0
Format:
[-]dddD  hh:mm[.ss[.xxx...]]
where
ddd	is number of days	(Blanked if day < 1)
hh	is number of hours
mm	is number of minutes
ss	is number of seconds (only if SECDEC >= 0)
xxx	is fraction of second with SECDEC digits
PUTTIME also returns a reference to parameter FIELD.
Thus it can be used as parameter to Outtext -
i.e.  Outtext(puttime(field,Time,'H',-1)
or editing Image directly -
      puttime(Image.Sub(Pos,17),Time,'H',-1)
C.f. procedure OUTTIME.
;
IF field.Length >=
(IF secdec < 0 THEN 12 ELSE IF secdec = 0 THEN 15 ELSE secdec+16)
THEN
BEGIN   INTEGER days,hours,m,powersec;   REAL seconds;
    PROCEDURE fixedit(x,w);   REAL x;   INTEGER w;
    BEGIN
	field.Sub(field.Pos,w).Putfix(x,secdec);
	field.Setpos(field.Pos+w);
    END of fixedit;
    PROCEDURE intedit(i,w);   INTEGER i,w;
    BEGIN
	field.Sub(field.Pos,w).Putint(i);
	IF field.Getchar = ' ' THEN
	BEGIN   field.Setpos(field.Pos-1);
	    field.Putchar('0');
	END;
	field.Setpos(field.Pos-1+w);
    END of intedit;
    BOOLEAN PROCEDURE adjusted;
    BEGIN
	IF m = 60 THEN
	BEGIN   adjusted:= TRUE;
	    hours:= hours + 1;   m:= 0;
	    IF hours = 24 THEN
	    BEGIN   days:= days + 1;   hours:= 0   END
	END;
	field.Sub(2,6):= "   D  ";
	field.Setpos(5);
	IF days < 1 THEN
	field.Putchar(' ') ELSE
	IF days < 10 THEN
	BEGIN
	    field.Setpos(4);
	    field.Putchar(Char(days+Rank('0')));
	END ELSE
	IF days < 100 THEN
	BEGIN   field.Setpos(3);   intedit(days,2)   END ELSE
	IF days < 1000 THEN
	BEGIN   field.Setpos(2);   intedit(days,3)   END ELSE
	IF days <= 9999 AND days >= -999 THEN
	BEGIN   field.Setpos(1);   intedit(days,4)   END ELSE
	field.Sub(1,4):= "****";
	field.Setpos(8);
	intedit(hours,2);   field.Putchar(':');
    END of adjust;
    powersec:= 1;
    FOR m:= 1 step 1 UNTIL secdec DO powersec:= powersec*10;
    IF unit = 'D' THEN time:= 1440*time ELSE
    IF unit = 'H' THEN time:= 60*time ELSE
    IF unit = 'M' THEN ELSE
    IF unit = 'S' THEN time:= time/60 ELSE
    BEGIN   putfloat(field,time);
	GO TO stop
    END;
    field.Setpos(1);
    field.Putchar(IF time < 0 THEN '-' ELSE ' ');
    time:= Abs(time);
    IF time > 34 359 738 367 THEN GO TO error;
    m:= Entier(time);
    seconds:= 60*(time - m);
    hours:= m//60;
    m:= Mod(m,60);
    days:= hours//24;
    hours:= Mod(hours,24);
    IF secdec >= 0 THEN
    BEGIN
	IF Entier(seconds*powersec+0.5) = 60*powersec THEN
	BEGIN   m:= m + 1;   seconds:= 0   END;
	adjusted;
	intedit(m,2);   field.Putchar('.');
	IF seconds < 9.5 THEN
	BEGIN   field.Putchar('0');
	    fixedit(seconds,IF secdec = 0 THEN 1 ELSE secdec+2)
	END ELSE
	fixedit(seconds,IF secdec = 0 THEN 2 ELSE secdec+3);
    END ELSE
    BEGIN   time:= m + seconds/60;
	m:= time;
	IF adjusted THEN time:= 0;
	IF time < 9.5 THEN   field.Putchar('0');
	secdec:= 0;
	fixedit(time,IF time < 9.5 THEN 1 ELSE 2)
    END;
    stop:
    field.Setpos(1);   puttime:- field
END of puttime OK ELSE
error:
BEGIN   field.Setpos(1);
    puttime:- putfloat(field,time);
END of puttime error;