program tkygraf3;                {Auswertung von Thermospannungsmessungen,}
                                {die mit TKMGRAF3 durchgefhrt wurden}
uses  dos,crt,graph;


const ba=$300;mxhi=120;myhi=150;hh1=15;hh2=15;myh=35;

var US,tem1,tem2,ur,Strom,tem1a,tem1b,tem2a,tem2b,u1a,u1b,u2a,u2b,dt : real;
    T1i,T2i,UThi,urri,ti: string[12];
    b1,b2,b4,b10,b11: char;
    Name,name1,name2,kk,bild1,bild2,bild3,bild4: string;
    tex,tex2 :{real; }Text;
    i,l,anz,anz0,imax,b3,ap,ep,b5,b6:integer;
    ers: array[1..100] of integer;
    h,k,nn : Integer;
    zeit,ut,tm1,tm2 : array[1..50] of Real;
    f : text;
    z0,z1,z2,z3,z4,z5: real;
    time,time1,time2:real;
    hun1,hun2,min1,min2,sec1,sec2,h1,h2:word;
    ax:real;
    ax_wort:string;

var graphdriver,graphmode:integer;
    mx,my,mym,xp,yp,x0,y0,j,find,d,nr,find1:integer;
    al0,al1,r,dx,dy,xl,yl,invdifx,xminT,xminU,xmaxT,xmaxU,yminT,ymaxT:real;
    xmin,xmax,x,y,ymin,ymax,difx,dify,invdify,deltax,deltay,yminU,ymaxU:real;
    strxmin,strxmax,strymin,strymax,strr,sanz:string;
    sxmin,sxmax,syminT,symaxT,syminU,symaxU,xr,yr,zx,zy,zxy,zxx,a,zeit1:real;
    symin,symax,rr,alpha,T:real;
    word1,word2,word3,word4,word5:string;
    xmintxt,xmaxtxt,ymintxt,ymaxtxt:integer;

    {$m 20000,0,400000}
procedure ig;
begin
graphdriver:=detect;
initgraph(graphdriver,graphmode,'c:\sprachen\tp\bgi');
end;

begin
repeat
 clrscr;
 writeln('Programm zur Auswertung von Thermospannungsmeáwerten, die mit');
 writeln('Hilfe des Programms tkmgraf3 aufgenommen wurden.');
 { port[$301]:=$33;}
 rr:=0;
 writeln('Eingabe des Namen der Datei, in der sich die Meáwerte befinden, die');
 write('ausgewertet werden sollen (ohne .tkx): ');
 readln(name);
 name:=name+'.tkx';
 write('Dateiformat X,Y (1) oder Y,X (2) ');readln(b6);
 write('Probennummer: ');readln(word1);
 write('Schichtdicke in nm: ');readln(word2);
 write('Meádatum: ');readln(word3);
 write('Meástrom in mA: ');readln(word4);
 writeln('Geben Sie die šberschrift der Grafik ein! (max. eine Zeile!)');
 readln(word5);
 write('Soll der Koordinatenursprung in der Grafik enthalten sein? (j/n) ');
 readln (b4);
 write('Standardgrafik? (j/n) ');readln(b10);
 write('Sind alle Eingaben richtig? (j/n)');readln(b11);
until b11='j';
{for b3:=1 to 2 do begin}
 assign(tex,name);
 reset(tex);
if b6=2 then begin
readln(tex,alpha);
readln(tex,T);end else begin
readln(tex,T);
readln(tex,alpha);end;

xmin:=T;xmax:=xmin;
ymin:=alpha;ymax:=ymin;

while (not eof(tex)) do begin
if b6=2 then begin
readln(tex,alpha);
readln(tex,T);end else begin
readln(tex,T);
readln(tex,alpha);end;
  if T<xmin then xmin:=T;
  if T>xmax then xmax:=T;
  if alpha<ymin then ymin:=alpha;
  if alpha>ymax then ymax:=alpha;
end;
close(tex);
ymin:=ymin-0.1*abs(ymin);ymax:=ymax+0.1*abs(ymax);
if b4='j' then begin
xmin:=0;
if ymin>0 then ymin:=0;
if ymax<0 then ymax:=0;end;
if b10='j' then begin
xmin:=0;xmax:=330;ymin:=-9;ymax:=2;end;
if ((b3=2)and(b10='j')) then begin
xmin:=0;xmax:=330;end;
ig;
mx:=getmaxx-20;my:=getmaxy-20;
mym:=round(myh*(my-myhi)/100)+myhi;
for i:=mxhi to mx do begin putpixel(i,myhi,1);
                           putpixel(i,my,1);end;
for i:=myhi to my do begin putpixel(mxhi,i,1);
                           putpixel(mx,i,1);end;

dx:=(xmax-xmin);
if dx>0 then begin
r:=1;
    if dx>=100 then begin
           while dx>=100 do begin
                            dx:=dx/10;
                            r:=r*10;
                            end;                           {Ermittlung des}
                     end;                                  {X-Rasters}
    while dx<10 do begin
                   dx:=dx*10;
                   r:=r/10;
                   end;
    if dx>50 then deltax:=10*r
    else if dx>20 then deltax:=5*r
    else deltax:=2*r;
    invdifx:=(mx-mxhi)/(xmax-xmin);
    find:=0;
    x:=int(xmin/deltax)*deltax;
    for j:=-1 to 12 do begin                               {Zeichnen des}
    xr:=x+j*deltax;                                        {X-Rasters und}
    xl:=mxhi+(-xmin+x+j*deltax)*invdifx;                   {Ermittlung der}
    x0:=round(xl);                                         {X-Skale}
    if (x0>=mxhi) and (x0<=mx) then begin
    if find=0 then begin sxmin:=xr;find:=1;end;
    sxmax:=xr;
    for i:=myhi to mym do begin
    putpixel(x0,i,8);
    end;
    for i:=mym to my do begin
    putpixel(x0,i,8);
    end;
    end;
    end;
x0:=round(mxhi-xmin*invdifx);
if (x0>=mxhi) and(x0<=mx) then begin
    for i:=myhi to my do begin
    putpixel(x0,i,4);
    end;
    end;
end;
{+++++++++++++++++++++++++++++}

xl:=mxhi+(-xmin+x+j*deltax)*invdifx;
dy:=ymax-ymin;
if dy>0 then begin
r:=1;
    if dy>=100 then begin
           while dy>=100 do begin
                            dy:=dy/10;
                            r:=r*10;
                            end;                           {Ermittlung des}
                     end;                                  {Y-Rasters}
    while dy<10 do begin
                   dy:=dy*10;
                   r:=r/10;
                   end;
    if dy>50 then deltay:=10*r
    else if dy>20 then deltay:=5*r
    else deltay:=2*r;
    y:=int(ymax/deltay)*deltay;
invdify:=(my-myhi)/(ymax-ymin);
    find:=0;
    for j:=-1 to 12 do begin
    yr:=y-j*deltay;
    yl:=myhi+(ymax-y+j*deltay)*invdify;
    y0:=round(yl);

if((y0>=myhi)and(y0<=my)) then begin                       {Zeichnen des}
    if find=0 then begin symax:=yr;find:=1;end;            {Y-Rasters und}
    symin:=yr;                                             {Ermittlung der}
 {if nr=9 then begin syminU:=symin;symaxU:=symax;end;
 if nr=10 then begin syminT:=symin;symaxT:=symax;end;  }
    for i:=mxhi to mx do begin                             {Y-Skale}
    putpixel(i,y0,8);
    end;
    end;
    end;

    xl:=mx-(xmax-sxmin)*invdifx;
    x0:=round(xl);xmintxt:=x0;
    for j:=myhi-10 to myhi do begin
    putpixel(x0,j,3);end;
    xl:=mx-(xmax-sxmax)*invdifx;
    x0:=round(xl);xmaxtxt:=x0;
    for j:=myhi-10 to myhi do begin
    putpixel(x0,j,3);end;
    yl:=myhi+(ymax-symin)*invdify;
    y0:=round(yl);ymintxt:=y0;
    for j:=mxhi-10 to mxhi do begin
    putpixel(j,y0,3);end;
    yl:=myhi+(ymax-symax)*invdify;
    y0:=round(yl);ymaxtxt:=y0;
    for j:=mxhi-10 to mxhi do begin
    putpixel(j,y0,3);end;

y0:=round(myhi+ymax*invdify);
if (y0>=myhi) and (y0<=my) then begin
    for i:=mxhi to mx do begin
    putpixel(i,y0,4);
    end; 
    end;
end;

reset(tex);
while not eof(tex) do begin
if b6=2 then begin
readln(tex,alpha);
readln(tex,T);end else begin
readln(tex,T);
readln(tex,alpha);end;
    x:=T;
    y:=alpha;                                             { Zeichnen der }
    x:=mxhi+(x-xmin)*invdifx;xp:=round(x);                { Meáwerte }
    y:=myhi+(ymax-y)*invdify;yp:=round(y);
    circle(xp,yp,2);
end;

str(sxmin:8:2,strxmin);
str(sxmax:8:2,strxmax);
str(symin:8:2,strymin);
str(symax:8:2,strymax);
 settextstyle(1,horizdir,1);
settextjustify(centertext,lefttext);
outtextxy(xmintxt,myhi-hh1,strxmin);
settextjustify(centertext,lefttext);                    { Beschriftung des}
outtextxy(xmaxtxt,myhi-hh1,strxmax);                    {  X-Y-Rasters    }
{ settextstyle(0,vertdir,1); }
settextjustify(righttext,centertext);
outtextxy(mxhi-hh1,ymaxtxt,strymax);
settextjustify(righttext,centertext);
outtextxy(mxhi-hh1,ymintxt,strymin);


 settextstyle(1,horizdir,1);                            { Beschriftung der }
settextjustify(centertext,lefttext);                    { Grafik           }
outtextxy(round((mxhi+mx)/2),myhi-hh2,'T in K');
 settextstyle(1,vertdir,1);
settextjustify(righttext,centertext);
outtextxy(mxhi-hh2,round((myhi+my)/2),'alpha in æV/K');
settextjustify(lefttext,centertext);
 settextstyle(0,horizdir,0);
outtextxy(15,75,'Probennr.: ');
outtextxy(150,75,word1);
outtextxy(round(mx/2),75,'Schichtdicke/nm: ');
outtextxy(round(mx/2+200),75,word2);
outtextxy(15,45,'Meádatum: ');
outtextxy(150,45,word3);
outtextxy(round(mx/2),45,'Meástrom/mA: ');
outtextxy(round(mx/2+200),45,word4);
outtextxy(15,15,word5);

close(tex);
readln;
closegraph;
{end;}
writeln;
writeln('Programmende.');
readln;
end.