uses dos, crt; var f: file; t: text; name, tmp: string; c: char; ask, linux, zoom: boolean; nc, ng, x, i, j, code: integer; ml: integer; y: array[1..15] of integer; r: word; min, max: real; sx, dx, up, dn, temp: real; tx, ty, mx, my, lc, cx, cy, zx, zy, last: integer; wx, wy: real; v: real; px: real; py: array[1..15] of real; function fe(filename: string): boolean; var f : file; begin assign(f,filename); reset(f,1); close(f); fe := (ioresult = 0) and (filename <> ''); end; function getcolumns(filename: string): integer; var f: file; t: integer; flag: boolean; begin t := 0; flag := false; assign(f, filename); reset(f,1); repeat blockread(f,c,1,r); if eof(f) then c := #10; case c of #13, #10:; #32, #9: if flag then begin t := t + 1; flag := false; end; else flag := true; end; until c = #10; if flag then t := t + 1; getcolumns := t; end; function getlines(filename: string): integer; var f: file;t: text;trp:string; l: integer; begin if linux then begin assign(f, filename); reset(f, 1); l := 0; repeat blockread(f,c,1,r); if eof(f) then c := #10; case c of #13: begin blockread(f,c,1,r); l := l + 1; end; #10: l:=l+1; end; until eof(f); close(f); getlines := l; end else begin assign(t, filename); reset(t); l:=0; repeat l:=l+1; readln(t,trp); until eof(t); getlines:=l; end; end; procedure grep(filename: string; column: integer; var min, max: real); var t: text; value: real; l : integer; myc: integer; begin l := 0; assign(t, filename); reset(t); repeat l := l + 1; for myc := 1 to nc do begin read(t, value); if (myc = column) and (l < ml) then begin if l = 1 then begin min := value; max := value; end else begin if value < min then min := value; if value > max then max := value; end; end; end; until eof(t); close(t); end; begin textcolor(7); name := ''; name:=paramstr(1); if name='' then begin write('File: '); readln(name); end; if name='' then halt(0) else if not fe(name) then begin writeln('File error!'); halt(1); end; nc := getcolumns(name); writeln('File has ', nc, ' columns'); {linux bug: '/l' forces linux file method} linux := false; for i := 1 to 9 do begin tmp := paramstr(i); if (tmp='/l')or(tmp='/linux')or(tmp='-l')or(tmp='-linux') then linux := true; end; ml := getlines(name); {writeln('File has ', ml, ' lines');} write('N. of graphs: '); readln(tmp); val(tmp,ng,code); case ng of 0: ng:=1; else if code<>0 then halt(0); end; write('X axis: '); readln(tmp); val(tmp,x,code); case x of 0: x:=1; else if code<>0 then halt(0); end; last := x; for i := 1 to ng do begin write('Y axis ',i,': '); readln(tmp); val(tmp,y[i],code); case y[i] of 0: begin last:=last+1;y[i]:=last;end; else if code<>0 then halt(0); end; last := y[i]; grep(name, y[i], min, max); if i = 1 then begin dn := min; up := max; end else begin if min < dn then dn := min; if max > up then up := max; end; end; grep(name, x, sx, dx); {zooming: '/z' forces zoom} zoom := false; for i := 1 to 9 do begin tmp := paramstr(i); if (tmp='/z')or(tmp='/zoom')or(tmp='-z')or(tmp='-zoom') then zoom := true; end; if zoom then begin writeln('X range'); write('Min: '); readln(tmp); val(tmp,min,code); case code of 0: if tmp<>'' then sx:=min; end; write('Max: '); readln(tmp); val(tmp,max,code); case code of 0: if tmp<>'' then dx:=max; end; writeln('Y range'); write('Min: '); readln(tmp); val(tmp,min,code); case code of 0: if tmp<>'' then dn:=min; end; write('Max: '); readln(tmp); val(tmp,max,code); case code of 0: if tmp<>'' then up:=max; end; end; {adjust empty range} if sx=dx then begin sx := sx - 1; dx := dx + 1; end; if dn=up then begin dn := dn - 1; up := up + 1; end; {write('Press Return to see the plot'); readln;} clrscr; writeln('X: ', trunc(sx), ' ',trunc(dx)); writeln('Y: ', trunc(dn), ' ',trunc(up)); temp:=(dx-sx)/6; sx := sx - temp; dx := dx + temp; temp:=(up-dn)/6; up := up + temp; dn := dn - temp; tx := 74; ty := 18; mx := round((80-tx)/2); my := round((25-ty)/2); wx := (dx-sx)/tx; wy := (up-dn)/ty; zx := trunc(-sx/wx); zy := trunc(-dn/wy); zx := zx + mx; zy := 25-(my+zy); if zx in [mx..80-mx] then begin for i := my to 25-my do begin gotoxy(zx,i); write('|'); end; gotoxy(zx,my); write('^'); end; if zy in [my..25-my] then begin for i := mx to 80-mx do begin gotoxy(i,zy); write('-'); end; gotoxy(80-mx,zy); write('>'); end; if (zx in [mx..80-mx]) and (zy in [my..25-my]) then begin gotoxy(zx,zy); write('+'); end; assign(t, name); reset(t); lc := 0; lc := 0; repeat lc := lc + 1; {if lc