program counter(input, output); (* counter: program counter Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ *) label 1; (* end of program *) const (* begin module version *) version = 1.00; (* of counter.p 2009 Apr 13 2009 Apr 13, 1.00: origin *) updateversion = 1.00; (* defines lowest acceptable current parameter file *) (* end module version *) (* begin module describe.counter *) (* name counter: program counter synopsis counter(input: in, output: out) files input: parameters to control the program. The file must contain the following parameters, on one line: number: an integer number to display width: the number of positions to use for the display output: messages to the user description Output the given number and then backspace. This allows a running counter to be displayed by a script. examples Example script: ******************************************************************************** #!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.00 of mk 2009 Apr 13 # 2009 Apr 13, 1.00: origin @ n = 0 echo -n "here we go! >" while ($n < 1000) echo "$n 5" | counter @ n = $n + 1 end echo "$n< done!" ******************************************************************************** documentation see also {module digitcounter in} scan.p author Thomas Dana Schneider bugs technical notes *) (* end module describe.counter *) var afile, (* file used by this program *) counterp, (* file used by this program *) bfile: text; (* file used by this program *) (* begin module halt *) procedure halt; (* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. *) begin writeln(output,' program halt.'); goto 1 end; (* end module halt version = 'delmod 6.16 84 mar 12 tds/gds'; *) (* begin module digitcounter *) procedure digitcounter(var afile: text; var counter, previous: integer); (* Make a digit counter on a single line. The digits are written and overwritten the next time by using control H. To initialize, set the 'previous' variable to zero. To terminate, put a "writeln(afile,'whateveryouwant');". If you put "write(afile,'babble-counter: ');" before the call, the numbers will show up on the same line and your message can indicate what the counter is about. *) const ordControlH = 8; (* the ordinal of control H so that we do not have to put an actual control H into the source code. The chr() of this will give the control H character *) var digits: integer; (* number of digits in in previous number *) digitcount: integer; (* index to digits *) begin if previous > 0 then begin (* backspace the PREVIOUS number of digits *) (* Compute the number of digits. For sequencenumber = 1000, we add an extra 0.5 to avoid rounding that would give 3 instead of 4 as the number of digits. Other cases work fine with this. *) digits := trunc(ln(previous+0.5)/ln(10)+1); { writeln(output, digits:1, ' ', counter:1); for digitcount := 1 to previous do write(output, 'H'); } for digitcount := 1 to digits do write(output, chr(ordControlH)); { writeln(output, digits:1, ' ', counter:1, ' ',previous:1); } end; write(output, counter:1); previous := counter; end; (* end module digitcounter version = 5.32; (@ of prgmod.p 2007 Mar 25 *) (* begin module counter.themain *) procedure themain(var afile, counterp, bfile: text); (* the main procedure of the program *) const ordControlH = 8; (* the ordinal of control H so that we do not have to put an actual control H into the source code. The chr() of this will give the control H character *) var parameterversion: real; (* parameter version number *) widthindex: integer; (* index for the width *) number: integer; (* the number to display *) width: integer; (* the number of characters used for the number *) { previous: integer; (* the number of characters used for the number *) } begin read(input, number, width); write(output, number: width); for widthindex := 1 to width do begin write(output, chr(ordControlH)); end; { previous := 0; digitcounter(output,number, previous) } end; (* end module counter.themain *) begin themain(afile, counterp, bfile); 1: end.