(*---------------------------------------------------------------------------
   :Program.    Kurve
   :Author.     Jörg Wesemann
   :Address.    Auf der Heide 10, 2807 Achim - Baden
   :Phone.      (0)4202 / 70658
   :Shortcut.   [jwe]
   :Version.    2.94
   :Date.       23.03.89
   :Copyright.  PD
   :Language.   Modula-II
   :Translator. M2Amiga
   :Imports.    JWELib: Parser
   :Update.     none.
   :Contents.   Berechnet Extremstellen einer Funktion
   :Remark.     none
---------------------------------------------------------------------------*)



IMPLEMENTATION MODULE extremstellen;

FROM SYSTEM 		IMPORT	FFP,ADR;
FROM FFPInOut		IMPORT	WriteReal,ReadReal;
FROM InOut 		IMPORT	Write,WriteString,WriteLn,WriteCard,OpenOutput,
				CloseOutput;
FROM startupproc 	IMPORT	CLS,crlf,cursorr,center,solve,m,n,fn,eps,string,
                       		nullbuffer,dateiabfrage,fragedatei,wptr;
FROM intervall 		IMPORT	kleinintervall;
FROM JWELIB 		IMPORT	parse;    
FROM Strings 		IMPORT	Length;    
FROM menu 		IMPORT	wartemenu;
FROM Intuition		IMPORT	WindowToFront;


PROCEDURE extremstellen;

CONST
  MAXFOUND = 20;

VAR
  x,dx,xmin,xmax 	: FFP;
  success, found 	: BOOLEAN;
  art,cfound	 	: CARDINAL;
  
BEGIN
  nullbuffer[2]:= "0.2";
  kleinintervall(nullbuffer,ADR("EXTREMSTELLEN - Intervall"));
  xmin:= parse(nullbuffer[1],0.0);
  dx:=   parse(nullbuffer[2],0.0);
  xmax:= parse(nullbuffer[3],0.0);
  art := CARDINAL(parse(nullbuffer[4],0.0));
  found := FALSE;
  cfound:= 0;
  WindowToFront(wptr);
  Write(CLS); 
  IF dateiabfrage THEN
    fragedatei();
  END;
  center("EXTREMSTELLENBESTIMMUNG"); WriteLn;
  center("-----------------------"); crlf(2);
  center("von"); crlf(2);
  cursorr( 20+(31-Length(string)) DIV 2 );
  WriteString("f(x) = ");
  WriteString(string); crlf(3);
  cursorr(23); WriteString("Xmin: "); WriteReal(xmin,m,n); cursorr(5);
  WriteString("Xmax: "); WriteReal(xmax,m,n); crlf(3);
  x:= solve(xmin,xmax,dx,1,art,success);
  IF success THEN
    REPEAT
      cursorr(26);
      IF fn(x,2) < -eps THEN
        WriteString("H ( ");
      ELSIF fn(x,2) > eps THEN WriteString("T ( ");
      ELSIF (fn(x,3)>eps) OR (fn(x,3)>-eps) THEN WriteString("S ( ");
      ELSE success := FALSE;
      END;						   (* IF 2	*)
      IF success THEN
        WriteReal(x,m,n); WriteString(" , "); WriteReal(fn(x,0),m,n);
        WriteString(" )"); WriteLn;
        found := TRUE;
        INC(cfound);
      END;					    	   (* IF 3	*)
      xmin := x + dx;
      x:= solve(xmin,xmax,dx,1,art,success);
    UNTIL NOT success OR (x>xmax) OR (cfound > MAXFOUND);  (* REPEAT 1	*)
  END;							   (* IF 1	*)
  IF found = FALSE THEN 
    cursorr(22);
    WriteString("Keine Extremstellen im Intervall gefunden"); WriteLn;
  END;
  WriteLn;
  CloseOutput;
  crlf(2); cursorr(22);
  WriteString("Bitte 'RETURN' drücken für MENU ");
  wartemenu;
END extremstellen;

END extremstellen.    
