{These functions and procedures perform some basic input/output duties. by C. S. Tritt April 14, 1986 vs. 3.0} type txt = string[60]; procedure getreal(var output: real; prompt: txt); {This procdure reads a value from the keyboard and converts it to a real number. The entry of a RETURN causes the value of output to be unchanged.} var good: boolean; input: string[20]; code: integer; begin repeat write(prompt); readln(input); val(input, output, code); if code = 0 then good := true else begin delete(input, code, 20); val(input, output, code); if code = 0 then good := true else writeln('Ill-formed number, try again!'); end; until good; end; {getreal} procedure getint(var output: integer; prompt: txt); {This procdure reads a value from the keyboard and converts it to a integer number. The entry of a RETURN causes the value of output to be unchanged.} var good: boolean; input: string[20]; code: integer; begin repeat write(prompt); readln(input); val(input, output, code); if code = 0 then good := true else begin delete(input, code, 20); val(input, output, code); if code = 0 then good := true else writeln('Ill-formed number, try again!'); end; until good; end; {getint} procedure putstring(stringvalue, what: txt; var where: text); {Write a string value to the desired device} begin writeln(where, what + stringvalue); end; procedure putreal(value: real; w, d: integer; what: txt; var where: text); {Write a real numeric value to a file} begin writeln(where, 'The value of ' + what + ' is ', value:w:d); end; {putreal} procedure echoreal(value: real; w, d: integer); {Echo a value that has been read to the screen} begin writeln('Value read was ', value:w:d); end; {echoreal} procedure iocheck(var goodio: boolean; what: txt); {Check for good i/o. Warn the user if there's a problem} begin goodio := (ioresult = 0); if not goodio then writeln(what); end; procedure calcheck(var flag: boolean; what: txt; var where: text); {Warn the user if there is an error in the calculations} begin if flag then begin writeln(where, what); flag := false; end; end; procedure wait; {Wait for the RETURN key to be pressed} var dummy: string[20]; begin write('Press RETURN for next screen'); readln(dummy); end; type strof14 = string[14]; procedure getlutz(var species: strof14; var parm: parmlist); {This procedure gets the species name and the Lutz parameters.} var parmfile: string[8]; parmtag: text; goodio: boolean; j: integer; begin writeln; {$I-} repeat repeat repeat repeat repeat repeat write('Enter DOS filename of Lutz parameter file: '); readln(parmfile); iocheck(goodio, 'Name too long.'); until goodio; assign(parmtag, parmfile +'.ltz'); iocheck(goodio, 'Filename incorrect.'); until goodio; reset(parmtag); iocheck(goodio, 'File not found.'); until goodio; readln(parmtag, species); iocheck(goodio, 'Incorrect Lutz file format'); until goodio; j := 0; repeat j := j + 1; read(parmtag, parm[j]); iocheck(goodio, 'Incorrect Lutz file format'); until (j = 10) or not goodio; until j = 10; close(parmtag); iocheck(goodio, 'Disk error closing Lutz file'); until goodio; {I+} end; procedure getroute(var ritefile: char; var desttag: text); {This procedure determines where to send the output.} var destfile: string[8]; goodio: boolean; begin repeat writeln; write('Results to disk (D), Printer (P) or screen (S)? '); read(kbd, ritefile); ritefile := upcase(ritefile); writeln; if (ritefile = 'S') then assign(desttag, 'con:'); if (ritefile = 'P') then assign(desttag, 'lst:'); if (ritefile = 'D') then {$I-} repeat repeat repeat writeln; write('Enter legal DOS filename for results file: '); readln(destfile); iocheck(goodio, 'Bad file name.'); until goodio; assign(desttag, destfile + '.out'); iocheck(goodio, 'Bad file name.'); until goodio; rewrite(desttag); iocheck(goodio, 'Bad file name.'); until goodio {$I+} until (ritefile = 'S') or (ritefile = 'P') or (ritefile = 'D'); writeln; end; {getroute} type methray = array[1..3] of string[10]; procedure getco2m(var co2meth: char; var co2mthno: integer; var method: methray); {This procedure gets the CO2 calculation method from the user.} begin repeat writeln('Enter the number of the CO2 content method to be used.'); writeln; writeln(' 1 - ' + method[1]); writeln(' 2 - ' + method[2]); writeln(' 3 - ' + method[3]); writeln; read(kbd, co2meth); case co2meth of '1' : co2mthno := 1; '2' : co2mthno := 2; '3' : co2mthno := 3; end; until (co2meth = '1') or (co2meth = '2') or (co2meth = '3'); end; {getco2m}