home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Applications / Mathematiques / Kurve.lha / Kurve / kurve.c < prev    next >
C/C++ Source or Header  |  1992-12-06  |  48KB  |  1,744 lines

  1. /*  kurvemake  */
  2. /* this is the name of the makefile */
  3. /*******************************************************************/
  4. /*                                                                 */
  5. /*                            Kurve                                */
  6. /*                                                                 */
  7. /*                       Kurvendiskusion                           */
  8. /*                                                                 */
  9. /*                   ⌐ 89-92 by Henning Rink                       */
  10. /*                                                                 */
  11. /*                Version 2.001               12.09.1992           */
  12. /*                                                                 */
  13. /*                                                                 */
  14. /* copyright notes -> see ReadMe                                   */
  15. /*******************************************************************/
  16.  
  17. /*******************************************************************/
  18. /*                                                                 */
  19. /*                      REVISION HISTORY                           */
  20. /*                                                                 */
  21. /* Kurve V1.0                                           10.09.1989 */
  22. /*                                                                 */
  23. /* Kurve V1.5                                           20.02.1990 */
  24. /* changed Parser 2.55 to 3.0                                      */
  25. /* Parser now creates code for pseudo-stack-machine                */
  26. /*                                                                 */
  27. /* Kurve V1.6                                           21.10.1990 */
  28. /* Updated whole programm for Aztec C 5.0a                         */
  29. /* new Funktion-Requester                                          */
  30. /* added zooming of coordinates                                    */
  31. /*                                                                 */
  32. /* Kurve V1.7                                           01.12.1990 */
  33. /* new Parser 4.00 now generates 68000 machine code for IEEE64 libs*/
  34. /* some minor changes in frequest.c                                */
  35. /*                                                                 */
  36. /* small changes in NeueF()                     V1.701  07.01.1991 */
  37. /* changed DoReq()                                      07.01.1991 */
  38. /* changed colours for WB 2.0 (got Kick36.141?) V1.702  19.01.1991 */
  39. /* some minor changes at pseudo bugs            V1.703  10.03.1991 */
  40. /* added UnZoom()                                       10.03.1991 */
  41. /* changed line-clipping code                   V1.704  19.03.1991 */
  42. /*                                                                 */
  43. /* Kurve V1.71 27.04.1991                                          */
  44. /* added screenprefs() and changed all? coordinates to             */
  45. /* relative screen height and width                     27.04.1991 */
  46. /*                                                                 */
  47. /* V1.711 changed Drucken() because I got a formfeed between       */
  48. /* close(fd[prt:]) (printing of the Text )                         */
  49. /* and the OpenDevice(printer...) (prints RastPort)                */
  50. /* this occur only with HP-Desk/Laserjet                27.05.1991 */
  51. /* added ShowErr()                                      28.05.1991 */
  52. /*                                                                 */
  53. /* V1.712 some code improvements, menu style change     15.06.1991 */
  54. /* no more dividing with constant floats->> multiply it!           */
  55. /*                                                                 */
  56. /* V1.713 small changes in all modules                  25.07.1991 */
  57. /*                                                                 */
  58. /* V1.714 changed Cross() and ZoomBox()                 10.08.1991 */
  59. /*                                                                 */
  60. /* V1.715 more 2.0 styling, translation german english             */
  61. /* corrected  g-format error -->>checkstring()  18. and 24.08.1991 */
  62. /*                                                                 */
  63. /* V1.716 WB like cycling of ZoomBox                    24.09.1991 */
  64. /*                                                                 */
  65. /* V1.800 added changescreensize requester,             17.11.1991 */
  66. /* changecolor request and some menu improvements                  */
  67. /* Deleted Funktion(), Ableitung1() and  Ableitung2()              */
  68. /* --> all drawing is done via DrawFunc()                          */
  69. /* Inserted getcolors();  enabled Keystroke Activation  18.11.1991 */
  70. /* of all Gadgets used in  Requesters                              */
  71. /* inserted new mousepointer                            19.11.1991 */
  72. /* added extLoadConfig and extSaveConfig to handle different       */
  73. /* configuration files                          19. and 20.11.1991 */
  74. /*                                                                 */
  75. /* V1.801 found bug in tag structure; changed Draw->All 17.12.1991 */
  76. /*                                                                 */
  77. /* V1.802 ShowErr now does AutoRequest, added numerical (Simpson)  */
  78. /* integration of the function from xmin to xmax        21.12.1991 */
  79. /*                                                                 */
  80. /* added #ifdef AztecVERSION500 to printpara() and checkstring()   */
  81. /* in funkrequest.c, so checkstring is only compiled if you set    */
  82. /* this define to AztecVERSION500 -> see checkstring()             */
  83. /* changed some cast operators and includes.kur cause I'm using    */
  84. /* now the Kick2.04 and AztecC52 includes               24.12.1991 */
  85. /* some minor enhancements                              25.12.1991 */
  86. /* placed file and screenrequest in fileandscreen.c     28.12.1991 */
  87. /* V1.803 last Aztec 5.0d/e Version                     28.12.1991 */
  88. /*                                                                 */
  89. /* V1.900  new functionlist requester and new intervall requester  */
  90. /* to deal with various number of functions  29.12.1991-06.02.1992 */
  91. /* recursive drawfunc2()                                08.02.1992 */
  92. /*                                                                 */
  93. /* V1.901                                                          */
  94. /* disabled load-save in Functionlist and found bug in disabling   */
  95. /* Colors Menu if no palette requester is available     28.02.1992 */
  96. /*                                                                 */
  97. /* V1.902 bug in doreqreq found !!                      17.04.1992 */
  98. /* now save and load settings always with the active function      */
  99. /* bug in load - save functions found; load buffer was to small    */
  100. /*                                                                 */
  101. /* Changes for Version 2.000                                       */
  102. /* doing CreateMenus()  disabled KickstartVersions<37   28.07.1992 */
  103. /* changescreenmode-request with kick 2.0 look   01. to 03.08.1992 */
  104. /* MouseCenterWin, new OK,Cancel Gadgets         03. to 04.08.1992 */
  105. /* handlepattern, handleedit                     04. to 05.08.1992 */
  106. /* changeintervall, asl filerequester                   06.08.1992 */
  107. /* showerr now does EasyRequest()                       12.08.1992 */
  108. /* min_open                                             13.08.1992 */
  109. /* turboparser4.00 for 68881/82                         16.08.1992 */
  110. /*                                                                 */
  111. /* V2.001 small change in fileandscreen->gadgethandling 12.09.1992 */
  112. /* improved handling of asl.requester some code cleanup 27.09.1992 */
  113. /*******************************************************************/
  114.  
  115.  
  116. /* externals in globdata.c  */
  117.  
  118. extern struct   NewWindow FirstNewWindow;
  119. extern struct   NewWindow SecondNewWindow;
  120. extern struct   NewWindow ThirdNewWindow;
  121. extern struct   NewWindow FourthNewWindow;
  122. extern struct   NewScreen FirstNewScreen; /* this is an ExtNewScreen !! */
  123. extern struct   TextAttr  NormalAttr;
  124. extern struct   IntuiText MemText;
  125. extern struct   IntuiText DateText;
  126. extern struct   IntuiText NameText;
  127. extern unsigned char      funktion[]; /* init with LoadConfig()   25.07.1991 */
  128. extern unsigned char      UndoBuffer[];
  129. extern unsigned char      minx[];
  130. extern unsigned char      maxx[];
  131. extern unsigned char      miny[];
  132. extern unsigned char      maxy[];
  133. extern          char      *Days[],*Months[],*ErrorMessages[];
  134. extern const    char      *coltoolname;
  135. extern UWORD              mousedata[];
  136. extern USHORT defscr;
  137. extern struct EasyStruct  es1;
  138.  
  139.  
  140. extern APTR     ScreenVI;
  141. extern struct   Menu       *menu;
  142. extern struct   NewMenu    menulist[];
  143. extern struct   NewGadget  NewOKGadget;
  144. extern struct   NewGadget  NewCancelGadget;
  145. extern struct   Gadget     *nullgadget;
  146.  
  147. /* externals from funkrequest.c and parser.c */
  148.  
  149. extern  double  x;
  150. extern  short   fehler;
  151. extern  short   *point;
  152. extern  void    FuncReq(void);
  153. extern  void    ZoomBox(USHORT);
  154. extern  void    UnZoom(void);
  155. extern  void    printpara(unsigned char *,double);
  156. extern  void    checkrights(char *);
  157. extern  void    changecolor(void);
  158. extern  void    changescreenmode(void);
  159. extern  void    extLoadConfig(void);
  160. extern  void    extSaveConfig(void);
  161. extern  void    LoadConfig(char *);
  162. extern  void    setcolors(void);
  163. extern  void    delallfuncs(void);
  164. extern  void    changeintervall(void);
  165. extern  void    helpdruck(UBYTE **, long *);
  166. extern  void    ReDrawFuncs(void);
  167. extern  void    MouseCenterWin(struct NewWindow *,short,short);
  168. extern  void    handlesave(void);
  169. extern  void    setscreenprefs(void);
  170.  
  171. /* internal functions  */
  172. void    Open_LIBS(void);
  173. void    Close_LIBS(void);
  174. void    Open_WINS(void);
  175. void    Close_WINS(void);
  176. void    About(void);
  177. void    Drucken(void);
  178. void    Ende(void);
  179. void    NeueP(void);
  180. void    DrawFunc(double (*)(double),long);
  181. void    Clear(void);
  182. void    Nullstellen(void);
  183. void    Maxima(void);
  184. void    Wendepunkte(void);
  185. void    Cross(void);
  186. void    Maus(void);
  187. void    newton1(short);
  188. void    newton2(short, double);
  189. void    newton3(short, double);
  190. short   openex(void);
  191. void    closeex(short);
  192. void    exaus(short,double,double,short);
  193. double  f(double);
  194. double  fa(double);
  195. double  fa2(double);
  196. double  fa3(double);
  197. WORD    Menuauswertung(USHORT);
  198. short   ShowErr(short,BOOL);
  199. void    NumIntegrate(double (*)(double));
  200. void    Cleardrawn(void);
  201. void    DrawFunc2(double (*)(double),double,long);
  202. void    Kickerror(void);
  203. void    min_open(void);
  204.  
  205. /* more vars   */
  206.  
  207. double  (*numb)(void);
  208. double  (*numb1)(void);
  209. double  (*numb2)(void);
  210. struct  FuncNode *FirstFunc;
  211. struct  FuncNode *activeFunc;
  212.  
  213. extern struct        ExecBase   *SysBase;
  214. struct ReqLib        *ReqBase;
  215. struct IntuitionBase *IntuitionBase;
  216. struct Library       *AslBase;
  217. struct Library       *GadToolsBase;
  218.  
  219.  
  220. struct Screen        *FirstScreen;
  221. struct Window        *FirstWindow,*SecondWindow,*ThirdWindow,*FourthWindow;
  222. struct IntuiMessage  *message;
  223. struct GfxBase       *GfxBase;
  224. struct RastPort      *rp,*rp2,*rp4;
  225. struct Process       *process;
  226. APTR                  oldwin;
  227.  
  228. double  xmin,xmax,ymin,ymax,xstep,xe,ye;
  229. long    xnull,ynull;      /* Nullpunkte */
  230. short   STEP=4;
  231. long    ys,xs,yn,xn,xmouse,ymouse;   /* Startendkoordinaten fⁿr Zoombox  */
  232. long    scrheight,scrwidth,winheightmax,scrmode;
  233. short   flag=0;
  234. UWORD   *mousemem;
  235.  
  236. extern struct IntuiText CopyrightText;
  237. extern char   configfile[];
  238. extern char   configpath[];
  239. extern char   configdir[];
  240. short array[1500];
  241.  
  242.  
  243. union printerIO  /* look for Addison Wesley  Libraries&Devices  */
  244.  {
  245.    struct IOStdReq    ios;
  246.    struct IODRPReq    iodrp;
  247.    struct IOPrtCmdReq iopc;
  248.  };
  249.  
  250.  
  251.  
  252. void    _cli_parse(){}
  253. void    _wb_parse(){}
  254.  
  255.  
  256. void main(void)
  257. {
  258.  register ULONG  MessageClass;
  259.  USHORT   Code,paint=0;
  260.  WORD     goon;
  261.  
  262.  if(SysBase->LibNode.lib_Version<37)  /* 28.07.1992 */
  263.    Kickerror();
  264.  
  265.  
  266.   xmin=sin(3.0)+sin(3.0);  /* ╓ffnen der Mathlibs   10.03.1991      */
  267.                            /* bei einem Fehler bricht das Programm */
  268.                            /* automatisch ab !!!                   */
  269.  
  270.  
  271.  Open_LIBS();
  272.  
  273.  strcpy(&configpath[0],&configdir[0]);
  274.  strcat(&configpath[0],&configfile[0]);
  275.  
  276.  LoadConfig(NULL);
  277.  
  278.  checkrights((char *)CopyrightText.IText);
  279.  
  280.  /* all screen configuration done !! */
  281.  /* so lets open my screen and windows */
  282.  
  283.  Open_WINS();
  284.  
  285.  
  286.    FOREVER
  287.     {
  288.       Wait(1L<<FirstWindow->UserPort->mp_SigBit);
  289.       while(message=(struct IntuiMessage *)GetMsg(FirstWindow->UserPort))
  290.        {
  291.            MessageClass=message->Class;
  292.            Code=message->Code;
  293.            xmouse=message->MouseX;
  294.            ymouse=message->MouseY;
  295.            ReportMouse((long)FALSE,FirstWindow);
  296.             
  297.  
  298.            if(MessageClass&MENUVERIFY)
  299.              {
  300.                    if(paint)
  301.                     {
  302.                       if(flag)
  303.                        ZoomBox(2);
  304.                        paint=0;
  305.                        if(Code==MENUHOT)
  306.                              message->Code=MENUCANCEL;
  307.                     }
  308.               }
  309.  
  310.            ReplyMsg((struct Message *)message);
  311.  
  312.           switch(MessageClass)
  313.            {
  314.               case MOUSEBUTTONS :
  315.                  switch(Code)
  316.                   {
  317.                     case SELECTUP :
  318.                         paint=0;
  319.                         if(flag)
  320.                            ZoomBox(paint);
  321.                         break;
  322.                     case SELECTDOWN : /* disabling menu messages  25.07.1991 */
  323.                       if(!paint)
  324.                          {
  325.                              paint=1;
  326.                              xs=xmouse;
  327.                              ys=ymouse;
  328.                          }
  329.                         break;
  330.                     }
  331.               break;  
  332.  
  333.               case INTUITICKS:  /* added 24.09.1991 */
  334.                    if(paint)
  335.                      ZoomBox(paint);
  336.                     break;
  337.  
  338.               case MOUSEMOVE :
  339.                     if(paint)
  340.                        ZoomBox(paint);
  341.                     Maus();
  342.                     break;
  343.  
  344.               case MENUPICK :
  345.                   if(Code!=MENUNULL)
  346.                    {
  347.                     goon=Menuauswertung(Code); /* got an endless loop of */
  348.                     while(goon)                /* NextSelect   so I must */
  349.                      {     /* have a return value  from Menuauswertung   */
  350.                            /* since doing CreateMenus()     28.07.1992   */
  351.                        Code=ItemAddress(menu,(long)Code)->NextSelect;
  352.                        if(Code!=MENUNULL)
  353.                          goon=Menuauswertung(Code);
  354.                        else
  355.                          break;
  356.                      }
  357.                    }
  358.                   break;
  359.  
  360.            }
  361.            ReportMouse((long)TRUE,FirstWindow);
  362.        }
  363.     }
  364. }
  365.  
  366.  
  367.  
  368. /******************************************/
  369. /*                                        */
  370. /*      Auswertung der Menunummer         */
  371. /*                                        */
  372. /******************************************/
  373.  
  374. WORD Menuauswertung(USHORT Menunummern)
  375. {
  376.   register USHORT Menu,MenuItem,SubItem;
  377.   WORD     retval=TRUE;
  378.  
  379.   Menu=MENUNUM(Menunummern);
  380.   MenuItem=ITEMNUM(Menunummern);
  381.   SubItem=SUBNUM(Menunummern);
  382.  
  383.  
  384.  SetDrMd(rp,(long)JAM1);
  385.  
  386.  switch(Menu)
  387.   {
  388.      case 0:
  389.           switch(MenuItem)
  390.              {
  391.                case 0:
  392.                     Cleardrawn();
  393.                     Clear();
  394.                     break;
  395.                case 1:
  396.                     About();
  397.                     break;
  398.                case 2:
  399.                     if(ShowErr(16,TRUE))
  400.                      Drucken();
  401.                     break;
  402.                case 3:
  403.                     if(ShowErr(0,TRUE))
  404.                     Ende();
  405.                     break;
  406.               }
  407.           break;
  408.  
  409.      case 1:
  410.           switch(MenuItem)
  411.             {
  412.                case 0:
  413.                  FuncReq();
  414.                break;
  415.  
  416.                case 1:
  417.                  changeintervall();
  418.                  break;
  419.  
  420.                case 2:
  421.                  UnZoom();
  422.                break;
  423.  
  424.                case 3:
  425.                   switch(SubItem) /* Schrittweite einstellen  */
  426.                    {
  427.                      case 0:
  428.                         STEP=1;
  429.                         xstep=(xmax-xmin)/scrwidth;
  430.                         break;
  431.                      case 1:
  432.                         STEP=2;
  433.                         xstep=(xmax-xmin)/scrwidth*2.0;
  434.                         break;
  435.                      case 2:
  436.                         STEP=4;
  437.                         xstep=(xmax-xmin)/scrwidth*4.0;
  438.                         break;
  439.                      case 3:
  440.                         STEP=8;
  441.                         xstep=(xmax-xmin)/scrwidth*8.0;
  442.                         break;
  443.                     }
  444.                  break;
  445.                case 4:
  446.                    changescreenmode();
  447.                    retval=FALSE;
  448.                    break;
  449.                case 5:
  450.                    changecolor();
  451.                    break;
  452.                case 6:
  453.                    extLoadConfig();
  454.                    retval=FALSE;
  455.                    break;
  456.                case 7:
  457.                    extSaveConfig();
  458.                    break;
  459.             } 
  460.           break;
  461.  
  462.      case 2:
  463.           switch(MenuItem)
  464.             {
  465.               case 0:
  466.                 activeFunc->isdrawn|=0x01;
  467.                 DrawFunc(f,1L);
  468.                 break;
  469.               case 1:
  470.                 activeFunc->isdrawn|=0x02;
  471.                 DrawFunc(fa,4L);
  472.                 break;
  473.               case 2:
  474.                 activeFunc->isdrawn|=0x04;
  475.                 DrawFunc(fa2,5L);
  476.                 break;
  477.               case 3:
  478.                 activeFunc->isdrawn|=0x07;
  479.                 DrawFunc(f,1L);
  480.                 DrawFunc(fa,4L);
  481.                 DrawFunc(fa2,5L);
  482.                 break;
  483.               case 4:
  484.                 Clear();
  485.                 ReDrawFuncs();
  486.                 break;
  487.             }
  488.           break;
  489.      case 3:
  490.           switch(MenuItem)
  491.            {
  492.               case 0:
  493.                 Nullstellen();
  494.                 break;
  495.  
  496.               case 1:
  497.                  Maxima();
  498.                  break;
  499.  
  500.               case 2:
  501.                 Wendepunkte();
  502.                 break;
  503.  
  504.               case 3:
  505.                 NumIntegrate(f);
  506.                 break;
  507.             }
  508.           break;
  509.    }
  510.  SetDrMd(rp,(long)JAM1|COMPLEMENT);
  511. return(retval);
  512. }
  513.  
  514.  
  515. void Open_LIBS(void)
  516.  {
  517.    extern struct Gadget FuncSaveGadget,FuncLoadGadget;
  518.  
  519.  
  520.    if(!(AslBase=(struct Library *)  /* asl and gadtools  on 28.07.1992 */
  521.        OpenLibrary((UBYTE *)"asl.library",37L)))
  522.      {
  523.       Close_LIBS();
  524.       exit(0);
  525.      }
  526.  
  527.    if(!(GadToolsBase=(struct Library *)
  528.        OpenLibrary((UBYTE *)"gadtools.library",37L)))
  529.      {
  530.       Close_LIBS();
  531.       exit(0);
  532.      }
  533.  
  534.  
  535.    ReqBase=(struct ReqLib *)OpenLibrary((UBYTE *)"req.library",0L);
  536.  
  537.    if(!(mousemem=AllocMem(72L,MEMF_CHIP)))
  538.     {
  539.      Close_LIBS();
  540.      exit(0);
  541.     }
  542.  
  543.    CopyMem((char *)&mousedata[0],(char *)mousemem,72L);
  544.  
  545.    if(!(GfxBase=(struct GfxBase *)
  546.        OpenLibrary((UBYTE *)"graphics.library",37L)))
  547.    {
  548.        Close_LIBS();
  549.        exit(0);
  550.    }
  551.  
  552.    if (!(IntuitionBase = (struct IntuitionBase *)
  553.          OpenLibrary((UBYTE *)"intuition.library", 37L)))
  554.       {
  555.          Close_LIBS();
  556.          exit(0);
  557.       }
  558.  
  559. }
  560.  
  561.  
  562. void Close_LIBS(void)
  563.  {
  564.     if (mousemem)        FreeMem(mousemem,72L);
  565.     if (AslBase)         CloseLibrary((struct Library *)AslBase);
  566.     if (GadToolsBase)    CloseLibrary((struct Library *)GadToolsBase);
  567.     if (ReqBase)         CloseLibrary((struct Library *)ReqBase);
  568.     if (GfxBase)         CloseLibrary((struct Library *)GfxBase);
  569.     if (IntuitionBase)   CloseLibrary((struct Library *)IntuitionBase);
  570.  }
  571.  
  572. void Open_WINS(void)
  573.  {
  574.    BPTR fh;
  575.  
  576.    extern struct NewWindow ReqNewWindow,FuncReqNewWindow;
  577.  
  578.    if(!(FirstScreen=OpenScreen(&FirstNewScreen)))
  579.        {
  580.         if(ScreenVI)  /* do not call min_open on  programmstart */
  581.           {           /* changed 13.08.1992                     */
  582.             min_open();
  583.             return();
  584.            }
  585.         else 
  586.         {
  587.          ShowErr(15,FALSE);
  588.          Ende();
  589.         }
  590.        }
  591.  
  592. ScreenVI=GetVisualInfo(FirstScreen,TAG_DONE);  /* 28.07.1992 */
  593.  
  594. NewOKGadget.ng_VisualInfo=NewCancelGadget.ng_VisualInfo=ScreenVI;
  595.  
  596. FirstNewWindow.Screen=SecondNewWindow.Screen=ThirdNewWindow.Screen=\
  597. FourthNewWindow.Screen=ReqNewWindow.Screen=FuncReqNewWindow.Screen=FirstScreen;
  598.  
  599.    if (!(FirstWindow = OpenWindow(&FirstNewWindow)))
  600.       {
  601.         ShowErr(15,FALSE);
  602.         Ende();
  603.       }
  604.  
  605.   process= (struct Process *) FindTask(NULL);
  606.   oldwin=process->pr_WindowPtr;
  607.   process->pr_WindowPtr=(APTR)FirstWindow;
  608.  
  609.  
  610.   if(!(menu=CreateMenusA(menulist,NULL))) /* 28.07.1992 */
  611.    {
  612.      ShowErr(17,FALSE);
  613.      Ende();
  614.    }
  615.   if(!LayoutMenusA(menu,ScreenVI,NULL))
  616.    {
  617.     ShowErr(17,FALSE);
  618.     Ende();
  619.    }
  620.  
  621.   if(!(SetMenuStrip(FirstWindow,menu))) /*  Menu aktivieren       */
  622.    {                                    /* Test since 25.07.1991 */
  623.      ShowErr(17,FALSE);
  624.      Ende();
  625.    }
  626.  
  627.   if(!ReqBase)
  628.    {
  629.     if(!(fh=Lock((UBYTE *)coltoolname,(long)ACCESS_READ)))
  630.      {
  631.        OffMenu(FirstWindow,(long)0x00a1);
  632.      }
  633.     else
  634.      UnLock(fh);
  635.    }
  636.  
  637. if (!(SecondWindow = OpenWindow(&SecondNewWindow)))
  638.       {
  639.         ShowErr(8,FALSE);
  640.         Ende();
  641.       }
  642.  
  643.  rp=FirstWindow->RPort;
  644.  rp2=SecondWindow->RPort;
  645.  
  646.  SetAPen(rp,5L);
  647.  SetBPen(rp,0L);
  648.  SetAPen(rp2,1L);
  649.  SetDrPt(rp,0xffff);
  650.  SetDrMd(rp,(long)JAM1);
  651.  
  652.  setcolors();
  653.  
  654.  Cross();
  655.  Maus();
  656.  
  657.  SetDrMd(rp,(long)JAM1|COMPLEMENT);
  658. }
  659.  
  660.  
  661. void Close_WINS(void)
  662. {
  663.   if (FirstWindow)   process->pr_WindowPtr=oldwin; /* Don't test oldwin!!  */
  664.                                            /* test FirstWindow  10.03.1991 */
  665.  
  666.   if (FirstWindow->MenuStrip)  ClearMenuStrip(FirstWindow);
  667.                             /* did only test FirstWindow before 25.07.1991 */
  668.  
  669.   if (menu)            FreeMenus(menu);
  670.   if (FirstWindow)     CloseWindow(FirstWindow);
  671.   if (SecondWindow)    CloseWindow(SecondWindow);
  672.   if (FirstScreen)     
  673.     {
  674.      FreeVisualInfo(ScreenVI);
  675.      CloseScreen(FirstScreen);
  676.     }
  677.  
  678.   FirstScreen=FirstWindow=SecondWindow=menu=0L;
  679.  
  680.                                           /* BUG !!! if reopen windows with */
  681. }                                         /* Open_WINS after Close_WINS AND */
  682.                                           /* then ran out of mem, I close   */
  683.                                           /* FirstWindow, but there is no   */
  684.                                           /* FirstWindow!       25.12.1991  */
  685.  
  686.  
  687. /******************************************/
  688. /*                                        */
  689. /*         Fenster mit Infotext           */
  690. /*                                        */
  691. /******************************************/
  692.  
  693. void About(void)
  694. {
  695.   ULONG MessageClass;
  696.   struct RastPort *rp3;
  697.   long memchip,memother;
  698.   time_t z;
  699.   UBYTE  speicher[40];
  700.   struct tm  *zeit;
  701.   short  offset;
  702.  
  703.   ThirdNewWindow.FirstGadget=NULL;
  704.  
  705.   time(&z);   /* Zeit als long Variable */
  706.   zeit=localtime((const time_t *)&z);  /* long Variable in Zeitstructur wandeln */
  707.   sprintf((char *)UndoBuffer,"%s %2d. %s %4d  %2d:%02d:%02d",Days[zeit->tm_wday],zeit->tm_mday,
  708.           Months[zeit->tm_mon],zeit->tm_year+1900,
  709.           zeit->tm_hour,zeit->tm_min,zeit->tm_sec);
  710.  
  711.   offset=200-TextLength(rp,(STRPTR)UndoBuffer,strlen((const char *)UndoBuffer))/2;
  712.  
  713.   DateText.IText=UndoBuffer;      /* Structuren vervollstΣndigen  */
  714.   DateText.LeftEdge=offset;
  715.  
  716.   memchip=AvailMem(MEMF_CHIP);
  717.   memother=AvailMem(MEMF_FAST);
  718.  
  719.   sprintf((char *)speicher,"%ld chip mem, %ld other mem",memchip,memother);
  720.   offset=200-TextLength(rp,(STRPTR)speicher,strlen((const char *)speicher))/2;
  721.  
  722.   MemText.IText=speicher;      /* Structuren vervollstΣndigen  */
  723.   MemText.LeftEdge=offset;
  724.  
  725.   MouseCenterWin(&ThirdNewWindow,0,0);
  726.  
  727.   if ((ThirdWindow = OpenWindow(&ThirdNewWindow))==NULL)
  728.       ShowErr(9,FALSE);
  729.   else
  730.     {
  731.     
  732.      rp3=ThirdWindow->RPort;
  733.      PrintIText(rp3,&NameText,0L,0L);
  734.        FOREVER
  735.          {
  736.   
  737.           if((message=(struct IntuiMessage *)
  738.             GetMsg(ThirdWindow->UserPort))==NULL)
  739.            {
  740.              Wait(1L << ThirdWindow->UserPort->mp_SigBit);
  741.              continue;
  742.            }
  743.             MessageClass=message->Class;
  744.             ReplyMsg((struct Message *)message);
  745.             switch(MessageClass)
  746.               {
  747.                  case MOUSEBUTTONS :
  748.                  CloseWindow(ThirdWindow);
  749.                  return();
  750.                }
  751.          }
  752.     }
  753. }
  754.  
  755.  
  756. /******************************************/
  757. /*                                        */
  758. /*    Ausgabe des Windows und der         */
  759. /*    Einstellungen auf den Drucker       */
  760. /*                                        */
  761. /******************************************/
  762.  
  763.  
  764. void Drucken(void)
  765. {
  766.   struct  MsgPort    *printerPort;
  767.   union   printerIO  *request;
  768.   UBYTE               *memblock;
  769.   long               len,col0,col2;
  770.  
  771.  
  772.   helpdruck(&memblock,&len);   /* inserted 29.01.1992 */
  773.  
  774.   if(!len)
  775.    return();
  776.  
  777.  SetPointer(FirstWindow,mousemem,16L,16L,0L,0L);
  778.  
  779.  if(printerPort=CreatePort(NULL,0L))
  780.  {
  781.   if(request=(union printerIO *)CreateExtIO(printerPort,
  782.               sizeof(union printerIO)))
  783.   {
  784.   if(!(OpenDevice((UBYTE *)"printer.device",0L,(struct IORequest *)request,0L)))
  785.    {
  786.      /* old sprintf() deleted   29.01.1992 */
  787.  
  788.      request->ios.io_Message.mn_ReplyPort=printerPort;
  789.      request->ios.io_Command=CMD_WRITE;
  790.      request->ios.io_Data=(APTR)memblock;
  791.      request->ios.io_Length=len;
  792.  
  793.      if(!(DoIO((struct IORequest *)request)))
  794.       {
  795.        col0=GetRGB4(FirstScreen->ViewPort.ColorMap,0L);
  796.        col2=GetRGB4(FirstScreen->ViewPort.ColorMap,2L);
  797.        SetRGB4(&FirstScreen->ViewPort,0L,15L,15L,15L);
  798.        SetRGB4(&FirstScreen->ViewPort,2L,0L,0L,0L);
  799.  
  800.                   /* Einstellungen fⁿr einen RastPort-Dump */
  801.  
  802.        request->iodrp.io_Command= PRD_DUMPRPORT;
  803.        request->iodrp.io_RastPort=rp;
  804.        request->iodrp.io_ColorMap=FirstScreen->ViewPort.ColorMap;
  805.        request->iodrp.io_Modes=FirstScreen->ViewPort.Modes;
  806.        request->iodrp.io_SrcX=0;    /*       LeftEdge -- TopEdge  !!             */
  807.        request->iodrp.io_SrcY=0;    /* so kann man auch einen Ausschnitt drucken */
  808.        request->iodrp.io_SrcWidth=scrwidth;
  809.        request->iodrp.io_SrcHeight=scrheight-10;
  810.        request->iodrp.io_Special= SPECIAL_FULLROWS | SPECIAL_FULLCOLS | SPECIAL_ASPECT;
  811.  
  812.        if(DoIO((struct IORequest *)request))/* wartet bis Drucker fertig ist */
  813.               fehler=10;                     /* SendIO wⁿrde im Programm fortfahren  */
  814.  
  815.       SetRGB4(&FirstScreen->ViewPort,0L,(col0>>8) & 0xf,(col0>>4) & 0xf,col0 & 0xf);
  816.       SetRGB4(&FirstScreen->ViewPort,2L,(col2>>8) & 0xf,(col2>>4) & 0xf,col2 & 0xf);
  817.      }
  818.     CloseDevice((struct IORequest *)request);
  819.    }
  820.   DeleteExtIO((struct IORequest *)request);
  821.   }
  822.   DeletePort(printerPort);
  823.  }
  824.  
  825.  ClearPointer(FirstWindow); /* 29.01.1992 */
  826.  FreeMem(memblock,len);
  827.  
  828.  
  829. }
  830.  
  831.  
  832. void Ende(void)
  833. {
  834.  delallfuncs();
  835.  Close_WINS();
  836.  Close_LIBS();
  837.  exit(0);
  838. }
  839.  
  840.  
  841. /**************************************************/
  842. /*                                                */
  843. /*    Einstellungen nach Neueingabe ⁿberprⁿfen    */
  844. /*                                                */
  845. /**************************************************/
  846.  
  847. void NeueP(void)
  848. {
  849.  register double help,xnd,ynd;
  850.  
  851.  xmin=atof((const char *)minx);
  852.  xmax=atof((const char *)maxx);
  853.  ymin=atof((const char *)miny);
  854.  ymax=atof((const char *)maxy);
  855.  
  856.  if(xmin>xmax)  /*  X-Werte vertauscht  */
  857.   {
  858.     help=xmin;
  859.     xmin=xmax;
  860.     xmax=help;
  861.   }
  862.  if(ymin>ymax)   /*  Y-Werte vertauscht  */
  863.   {
  864.     help=ymin;
  865.     ymin=ymax;
  866.     ymax=help;
  867.   }
  868.  
  869.   printpara(minx,xmin);  /* Werte nochmals reinschreiben ,um   */
  870.   printpara(miny,ymin);  /* falsche Eingaben dem Benutzer beim */
  871.   printpara(maxx,xmax);  /* nΣchsten Aufruf sichtbar zu machen */
  872.   printpara(maxy,ymax);
  873.  
  874.   xstep=(xmax-xmin)/scrwidth*STEP;
  875.  
  876.   xe=scrwidth/(xmax-xmin);     /*  Schrittweite X         1Pixel  */
  877.   xnd=xe*-xmin;                /*  Nullpunkt    X                 */
  878.  
  879.   ye=(scrheight-10)/(ymax-ymin);     /*  Schrittweite Y   1 Pixel */
  880.   ynd=(scrheight-10)-ye*-ymin;       /*  Nullpunkt    Y           */
  881.  
  882.   xnull=xnd;              /* long Variablen mit Nullpunkt */
  883.   ynull=ynd;
  884.  
  885.  
  886. }
  887.  
  888. /*******************************************************************/
  889. /*                                                                 */
  890. /*               DrawFunc() is a revision of the old               */
  891. /*                 Ableitung1() --> so Funktion(),                 */
  892. /*                 Ableitung() and Ableitung2() is                 */
  893. /*                      done with DrawFunc()                       */
  894. /*              ->code size improvement of 860 bytes               */
  895. /*                                                                 */
  896. /*******************************************************************/
  897.  
  898. void DrawFunc(double (*calc)(double),long color)
  899. {
  900.   register  double y,x1;
  901.   register  long   xp,yp;
  902.   long      oldy;
  903.   short            flag=0;
  904.   UWORD     oldpattern;
  905.  
  906.    if(fehler)
  907.     return();
  908.    
  909.    oldpattern=rp->LinePtrn;
  910.    SetPointer(FirstWindow,mousemem,16L,16L,0L,0L);
  911.    SetAPen(rp,color);
  912.    SetDrPt(rp,activeFunc->FuncPattern);
  913.  
  914.    x1=xmin;
  915.    y=calc(x1);
  916.    yp=y*ye;
  917.    yp=ynull-yp;
  918.  
  919.    xp=xmin*xe;
  920.  
  921.   if(yp>winheightmax)
  922.      {
  923.       yp=winheightmax;
  924.       flag=1;
  925.      }
  926.   else
  927.      if(yp<0L)
  928.        {
  929.          yp=0L;
  930.          flag=1;
  931.        }
  932.  
  933.   oldy=yp;
  934.   Move(rp,0L,yp);
  935.  
  936.   for(;x1<xmax;x1 += xstep)
  937.    {
  938.      y=calc(x1);
  939.  
  940.      yp=-y*ye;
  941.      yp+=ynull;
  942.      xp=x1*xe;
  943.      xp += xnull;
  944.  
  945. /*  more Line-Clipping                        */
  946. /*  changed 19.03.1991 and 27.04.1991         */
  947. /*  old Version draws a line to y=251 or y=-1 */
  948. /*  this never caused a guru, but i thought   */
  949. /*  my old A2000 A (built 23-Jun-87) machines */
  950. /*  behavior is not like everyone's           */
  951.  
  952.      if(yp>winheightmax)
  953.       {
  954.        if(flag)
  955.         Move(rp,xp,winheightmax);
  956.        else
  957.         {
  958.          if(labs(yp-oldy)>(STEP<<2))
  959.             DrawFunc2(calc,xstep,yp);
  960.          Draw(rp,xp,winheightmax);
  961.          flag=1;
  962.         }
  963.       }
  964.      else
  965.       {
  966.        if(yp<0L)
  967.          {
  968.           if(flag)
  969.             Move(rp,xp,0L);
  970.           else
  971.            {
  972.              if(labs(yp-oldy)>(STEP<<2))
  973.                DrawFunc2(calc,xstep,yp);
  974.              Draw(rp,xp,0L);
  975.              flag=1;
  976.            }
  977.          }
  978.         else
  979.           {
  980.            if(labs(yp-oldy)>(STEP<<2))
  981.               DrawFunc2(calc,xstep,yp);
  982.             Draw(rp,xp,yp);
  983.             flag=0;
  984.           }
  985.        }
  986.      oldy=yp;
  987.    }
  988.   ClearPointer(FirstWindow);
  989.   SetDrPt(rp,oldpattern);
  990. }
  991.  
  992.  
  993. /*******************************************************************/
  994. /*                                                                 */
  995. /*       DrawFunc2() draws one new step if delta y is to big       */
  996. /*                         done 08.02.1992                         */
  997. /*                                                                 */
  998. /*******************************************************************/
  999.  
  1000. void DrawFunc2(double (*calc)(double),double oldstep,long oldy)
  1001. {
  1002.   double   xold,step;
  1003.   register long   xp,yp;
  1004.  
  1005.    step=oldstep*0.5;
  1006.  
  1007.    xold=x;
  1008.  
  1009.    yp=-calc(x-step)*ye;
  1010.    yp+=ynull;
  1011.    xp=x*xe;      /* x is set while doing calc(x-step) */
  1012.    xp += xnull;
  1013.  
  1014.   if(yp>winheightmax)
  1015.       yp=winheightmax;
  1016.   else if(yp<0L)
  1017.         yp=0L;
  1018.  
  1019.   if(labs(yp-oldy)>(STEP<<2))
  1020.    DrawFunc2(calc,step,yp);
  1021.  
  1022.   Draw(rp,xp,yp);
  1023.  
  1024.   x=xold;
  1025. }
  1026.  
  1027.  
  1028. /*******************************************************************/
  1029. /*                                                                 */
  1030. /*             Cleardrawn clears the isdrawn Flag in               */
  1031. /*             struct FuncNode       done 23.01.1992               */
  1032. /*                                                                 */
  1033. /*******************************************************************/
  1034.  
  1035. void Cleardrawn(void)
  1036. {
  1037.  struct FuncNode *nodeptr;
  1038.  
  1039.  nodeptr=FirstFunc;
  1040.  
  1041.  do
  1042.   {
  1043.     nodeptr->isdrawn=0;
  1044.   }while(nodeptr=nodeptr->Next);
  1045. }
  1046.  
  1047. void Clear(void)   /*     Bildschirm l÷schen   */
  1048. {
  1049.  SetRast(rp,0L);
  1050.  Cross();
  1051. }
  1052.  
  1053.  
  1054. /******************************************/
  1055. /*                                        */
  1056. /*            Nullstellensuche            */
  1057. /*                                        */
  1058. /******************************************/
  1059.  
  1060. void Nullstellen(void)
  1061. {
  1062.    short n=0,sign,sign2;
  1063.    register    double dx,z;
  1064.  
  1065.    if(openex())
  1066.      return();
  1067.  
  1068.    Move(rp4,156L,20L);     /* Text ausgeben */
  1069.    Text(rp4,(UBYTE *)"Zero points",11L);
  1070.  
  1071.    x=xmin;
  1072.      sign=numb() < 0.0 ? 0 : 1;
  1073.  
  1074.    dx=(xmax-xmin)/scrwidth*4.0;  /* Schrittweite 4 Pixel  */
  1075.  
  1076.    for(;x<=xmax;x += dx)
  1077.     {
  1078.       sign2=numb() < 0.0 ? 0 : 1;
  1079.  
  1080.       if(sign != sign2 )
  1081.        {
  1082.            z=x;
  1083.            x -= dx*.5;
  1084.            n++;           /* ZΣhler der Nullstellen   */
  1085.            newton1(n);
  1086.            x = z;
  1087.            sign=sign2;
  1088.        }
  1089.      }
  1090.  
  1091. closeex(n);
  1092.  
  1093. }
  1094.  
  1095.  
  1096. /******************************************/
  1097. /*                                        */
  1098. /*        Ausgabewindow ÷ffnen            */
  1099. /*                                        */
  1100. /******************************************/
  1101.  
  1102. short openex(void)
  1103. {
  1104.  
  1105. if (!(FourthWindow = OpenWindow(&FourthNewWindow)))
  1106.       {
  1107.         ShowErr(12,FALSE);
  1108.         return(1);
  1109.       }
  1110.  
  1111.    rp4=FourthWindow->RPort;
  1112.    SetAPen(rp4,6L);
  1113.    SetBPen(rp4,0L);
  1114.  return(0);
  1115. }
  1116.  
  1117.  
  1118. /******************************************/
  1119. /*                                        */
  1120. /*       Ausgabewindow schlie▀en          */
  1121. /*                                        */
  1122. /******************************************/
  1123.  
  1124. void closeex(short n)
  1125. {
  1126.  long yoffset;
  1127.  
  1128.    yoffset=50+n*10;
  1129.  
  1130.    if(yoffset>(scrheight-15L))
  1131.      Move(rp4,184L,scrheight-18L);     /* Text ausgeben */
  1132.    else 
  1133.      Move(rp4,184L,yoffset);
  1134.  
  1135.    SetAPen(rp4,6L);
  1136.    Text(rp4,(UBYTE *)"End",3L);
  1137.  
  1138.    Wait(1L<<FourthWindow->UserPort->mp_SigBit);
  1139.    message=(struct IntuiMessage *)GetMsg(FourthWindow->UserPort);
  1140.  
  1141.    ReplyMsg((struct Message *)message);
  1142.  
  1143.    CloseWindow(FourthWindow);
  1144.  
  1145. }
  1146.  
  1147.  
  1148. /******************************************/
  1149. /*                                        */
  1150. /*     Ausgabe der gefundenen Stellen     */
  1151. /*                                        */
  1152. /******************************************/
  1153.  
  1154. void exaus(short n,double a,double b,short s)
  1155. {
  1156.     long offset=30+n*10;
  1157.  
  1158.     sprintf((char *)UndoBuffer,"y=%12.8f  at  x= %12.8e",a,b);
  1159.  
  1160.     if(offset>((scrheight/10)*10-30))
  1161.       {
  1162.         offset=(scrheight/10)*10-30;
  1163.         ScrollRaster(rp4,0L,10L,18L,32L,395L,scrheight-25L);
  1164.       }
  1165.     Move(rp4,20L,offset);
  1166.     SetAPen(rp4,1L);
  1167.     Text(rp4,(UBYTE *)UndoBuffer,strlen((const char *)UndoBuffer));
  1168.    
  1169.     if(s)
  1170.       {
  1171.         SetAPen(rp4,4L);
  1172.         Move(rp4,360L,offset);
  1173.         switch(s)
  1174.          {
  1175.            case 1:
  1176.               Text(rp4,(UBYTE *)"Max",3L);
  1177.               break;
  1178.            case 2:
  1179.               Text(rp4,(UBYTE *)"Min",3L);
  1180.               break;
  1181.            case 3:
  1182.               Text(rp4,(UBYTE *)"T",1L);
  1183.               break;
  1184.            case 4:
  1185.               Text(rp4,(UBYTE *)"S",1L);
  1186.               break;
  1187.          }
  1188.       }
  1189. }
  1190.  
  1191.  
  1192. /******************************************/
  1193. /*                                        */
  1194. /*    Ermitteln der Nullstelle            */
  1195. /*                                        */
  1196. /******************************************/
  1197.  
  1198. void newton1(short n)
  1199. {
  1200.   register  double x1,y1,y2;
  1201.   short q=0;
  1202.  
  1203.   x1=x;
  1204.   y1=numb();
  1205.  
  1206.   do
  1207.    {
  1208.      x += 1e-7;
  1209.      y2=numb();
  1210.  
  1211.      x1=x1-y1/((y2-y1)*1e7);
  1212.      
  1213.      x=x1;
  1214.      y1=numb();
  1215.  
  1216.      q++;
  1217.     }while((fabs(y1)>0.00001) && q<60);
  1218.  
  1219.      exaus(n,y1,x1,0);
  1220. }
  1221.  
  1222.  
  1223. /******************************************/
  1224. /*                                        */
  1225. /*          Maximasuche                   */
  1226. /*                                        */
  1227. /******************************************/
  1228.  
  1229. void Maxima(void)
  1230. {
  1231.  short n=0,sign,sign2;
  1232.  register double dx,z,x1;
  1233.  
  1234.   if(openex())
  1235.    return();
  1236.  
  1237.   SetAPen(rp4,6L);
  1238.   Move(rp4,140L,20L);
  1239.   Text(rp4,(UBYTE *)"Maxima & Minima",15L);
  1240.  
  1241.   x1=xmin;
  1242.   dx=(xmax-xmin)/scrwidth*8.0;
  1243.   sign=fa(x1)<0.0 ? 0 : 1;
  1244.  
  1245.   for(;x1<=xmax;x1 += dx)
  1246.    {
  1247.      sign2=fa(x1)<0.0 ? 0 : 1;
  1248.      if(sign != sign2)
  1249.       {
  1250.         z=x1;
  1251.         x1 -= dx*.5;
  1252.         n++;
  1253.         newton2(n,x1);
  1254.         x1=z;
  1255.         sign=sign2;
  1256.       }
  1257.     }
  1258.  closeex(n);
  1259.  
  1260. }
  1261.  
  1262.  
  1263. /******************************************/
  1264. /*                                        */
  1265. /*         Ermittlung des Maximas         */
  1266. /*                                        */
  1267. /******************************************/
  1268.  
  1269. void newton2(short n,double x1)
  1270. {
  1271.  register double y1,y;
  1272.  short q=0,s;
  1273.  
  1274.  y1=fa(x1);
  1275.  
  1276.  do
  1277.   {
  1278.     x1=x1-fa(x1)/fa2(x1);
  1279.  
  1280.     y1=fa(x1);
  1281.     q++;
  1282.   }while((fabs(y1)>0.001)&&q<60);
  1283.  
  1284.   x=x1;
  1285.   if(fa2(x1)<0.0)
  1286.     s=1;
  1287.   else
  1288.     s=2;
  1289.   y=numb();
  1290.  
  1291.   exaus(n,y,x1,s);
  1292.  
  1293. }
  1294.  
  1295.  
  1296. /******************************************/
  1297. /*                                        */
  1298. /*         Wendepunktsuche                */
  1299. /*                                        */
  1300. /******************************************/
  1301.  
  1302. void Wendepunkte(void)
  1303. {
  1304.  short n=0,sign,sign2;
  1305.  register double dx,z,x1;
  1306.  
  1307.  
  1308.  if(openex())
  1309.    return();
  1310.  
  1311.   SetAPen(rp4,6L);
  1312.   Move(rp4,144L,20L);
  1313.   Text(rp4,(UBYTE *)"Turning points",14L);
  1314.  
  1315.   x1=xmin;
  1316.   dx=(xmax-xmin)/scrwidth*8.0;
  1317.   sign=fa2(x1)<0.0 ? 0 : 1;
  1318.  
  1319.   for(;x1<=xmax;x1 += dx)
  1320.    {
  1321.     sign2=fa2(x1)<0.0 ? 0 : 1; 
  1322.      if(sign != sign2)
  1323.       {
  1324.         z=x1;
  1325.         x1 -= dx*.5;
  1326.         n++;
  1327.         newton3(n,x1);
  1328.         x1=z;
  1329.         sign=sign2;
  1330.       }
  1331.     }
  1332.  closeex(n);
  1333.  
  1334. }
  1335.  
  1336.  
  1337. /******************************************/
  1338. /*                                        */
  1339. /*       Ermittlung des Wendepunktes      */
  1340. /*                                        */
  1341. /******************************************/
  1342.  
  1343. void newton3(short n,double x1)
  1344. {
  1345.  register double y1,y;
  1346.  short q=0,s=3;
  1347.  
  1348.  y1=fa2(x1);
  1349.  
  1350.  do
  1351.   {
  1352.     x1=x1-fa2(x1)/fa3(x1);     /* x2=x1-f(x1)/f'(x1)  */
  1353.  
  1354.     y1=fa2(x1);
  1355.     q++;
  1356.   }while((fabs(y1)>0.001)&&q<60);
  1357.   
  1358.   x=x1;
  1359.   if(fabs(fa(x1))<0.1)
  1360.     s=4;
  1361.   y=numb();
  1362.  
  1363.   exaus(n,y,x1,s);
  1364. }
  1365.  
  1366.  
  1367. /******************************************/
  1368. /*                                        */
  1369. /*       Koordinatenkreuz zeichnen        */
  1370. /*                                        */
  1371. /******************************************/
  1372.  
  1373. void Cross(void)
  1374.  {
  1375.   register double z;
  1376.   register long   s;
  1377.   double   zadd;
  1378.  
  1379.   SetAPen(rp,2L);
  1380.  
  1381.                           /*   Achsen zeichnen   */
  1382.  
  1383. if(ynull>=0 && ynull<=winheightmax) /*      X-Achse        */
  1384.  {
  1385.   Move(rp,0L,ynull);
  1386.   Draw(rp,scrwidth-1L,ynull);
  1387.  
  1388.    zadd=pow(10.0,floor(log10(xmax-xmin)-0.7)); /* 20 minutes of thinking    */
  1389.    z=floor(xmin/zadd)*zadd+zadd;               /* 1h work, but great effect */
  1390.                                                /* changed 10.08.1991        */
  1391.                                                /* -0.7 gives 50 Steps       */
  1392.                                                /* -> 10^(1.7)=50.???        */
  1393.    do             /*   Einheiten zeichnen  */
  1394.     {
  1395.       s=xe*z+xnull;
  1396.       Move(rp,s,ynull-3L);         /* auf X-Achse   */
  1397.       Draw(rp,s,ynull+3L);
  1398.       z+=zadd;
  1399.     }while(z<=xmax);
  1400.  }
  1401.  
  1402. if(xnull>=0 && xnull<=scrwidth)    /*      Y-Achse        */
  1403.  {
  1404.    Move(rp,xnull,0L);
  1405.    Draw(rp,xnull,winheightmax);
  1406.  
  1407.    zadd=pow(10.0,floor(log10(ymax-ymin)-0.55));/* -0.55 gives me 35 steps */
  1408.    z=floor(ymin/zadd)*zadd+zadd;
  1409.  
  1410.    do
  1411.      {
  1412.        s=-ye*z+ynull;
  1413.        Move(rp,xnull-6L,s);         /* auf Y-Achse   */
  1414.        Draw(rp,xnull+6L,s);
  1415.        z+=zadd;
  1416.      }while(z<=ymax);
  1417.   }
  1418.  
  1419. }
  1420. /******************************************/
  1421. /*                                        */
  1422. /*                Function                */
  1423. /*                                        */
  1424. /******************************************/
  1425.  
  1426. double f(double r)  /* 17.11.1991 */
  1427. {
  1428.  x=r;
  1429.  return(numb());
  1430. }
  1431.  
  1432. /******************************************/
  1433. /*                                        */
  1434. /*             1. Ableitung               */
  1435. /*                                        */
  1436. /******************************************/
  1437.  
  1438. double fa(double r)
  1439. {
  1440.   register double x1,x2;
  1441.  
  1442.   x=r;
  1443.  
  1444.   if(numb1)
  1445.     return(numb1());
  1446.  
  1447.   x1=numb();
  1448.   x += 1e-6;
  1449.   x2 = numb();
  1450.  
  1451.   /*  (f(x+dx)-f(x))/dx  */
  1452.  
  1453.   return((x2-x1)*1e6);
  1454. }
  1455.  
  1456.  
  1457. /******************************************/
  1458. /*                                        */
  1459. /*             2. Ableitung               */
  1460. /*                                        */
  1461. /******************************************/
  1462.  
  1463. double fa2(double r)
  1464. {
  1465.   register double x1,x2; 
  1466.   double x3;
  1467.  
  1468.   x=r;
  1469.  
  1470.   if(numb2)
  1471.    return(numb2());
  1472.  
  1473.   x1=numb();
  1474.   x += 1e-5;
  1475.   x2=numb();
  1476.   x += 1e-5;
  1477.   x3=numb();
  1478.  
  1479. /*  f''(x)=(f(x+2dx)-2f(x+dx)+f(x))/dx^2 */
  1480.  
  1481.   return((x3-2.0*x2+x1)*1e10);
  1482.  
  1483. }
  1484.  
  1485.  
  1486. /******************************************/
  1487. /*                                        */
  1488. /*             3. Ableitung               */
  1489. /*                                        */
  1490. /******************************************/
  1491.  
  1492. double fa3(double r)
  1493. {
  1494.  register double x2,x3;
  1495.  double x1,x4;
  1496.  
  1497.  x=r;
  1498.  x1=numb();
  1499.  x += 1e-3;
  1500.  x2=numb();
  1501.  x += 1e-3;
  1502.  x3= numb();
  1503.  x += 1e-3;
  1504.  x4=numb();
  1505.  
  1506.  /* f'''(x)=(f(x+3dx)-3f(x+2dx)+3f(x+dx)-f(x))/dx^3  */
  1507.  
  1508.  return((x4-3.0*x3+3.0*x2-x1)*1e9);
  1509.  
  1510. }
  1511.  
  1512.  
  1513. /************************************************/
  1514. /*                                              */
  1515. /* abolute Koordinaten ins 2. Fenster schreiben */
  1516. /*                                              */
  1517. /************************************************/
  1518.  
  1519. void Maus(void)
  1520. {
  1521.  double mfy,mfx;
  1522.  char zahlx[15],zahly[15];
  1523.  
  1524.    mfy=(ynull-ymouse)/ye;       /*  x-Wert errechnen  */
  1525.    mfx=(xmouse-xnull)/xe;       /*  y-Wert errechnen  */
  1526.  
  1527.    sprintf(zahlx,"x= %-11.3e",mfx);
  1528.    sprintf(zahly,"y= %-11.3e",mfy);
  1529.  
  1530.       
  1531.     /* Text ausgeben */
  1532.    Move(rp2,4L,19L);
  1533.    Text(rp2,(UBYTE *)zahlx,14L);
  1534.    Move(rp2,4L,30L);
  1535.    Text(rp2,(UBYTE *)zahly,14L);
  1536.  
  1537. }
  1538.  
  1539.  
  1540. /*******************************************************************/
  1541. /*                                                                 */
  1542. /*           added this function cause I have a lott of            */
  1543. /*                 messages called in this form                    */
  1544. /*                                                                 */
  1545. /*                changed ShowErr on 12.08.1992                    */
  1546. /*       removed AutoRequest()   EasyRequest() is much better      */
  1547. /*******************************************************************/
  1548.  
  1549. short ShowErr(short num,BOOL extra)
  1550. {
  1551.   ULONG idcmp=0;
  1552.  
  1553.   fehler=0;    /* clear error number from parser  */
  1554.  
  1555.   if(extra)
  1556.     es1.es_GadgetFormat=(UBYTE *)"Ok|Cancel";
  1557.   else
  1558.     es1.es_GadgetFormat=(UBYTE *)"Ok";
  1559.  
  1560.    return(EasyRequestArgs(FirstWindow,&es1,&idcmp,&ErrorMessages[num]));
  1561. }
  1562.  
  1563.  
  1564. /*******************************************************************/
  1565. /*                                                                 */
  1566. /*      NumIntegrate() Integrates numerical the function f(x)      */
  1567. /*             from xmin to xmax via Simpson Integral              */
  1568. /*                                                                 */
  1569. /*******************************************************************/
  1570.  
  1571.  
  1572. void   NumIntegrate(double (*calc)(double))
  1573. {
  1574.  register  double f,x1;
  1575.  double    xs;
  1576.  short     n,i;
  1577.  ULONG     MessageClass;
  1578.  USHORT    code,qualifier;
  1579.  SHORT     GadgetID=0;
  1580.  char      str1[60],str2[30],str3[30];
  1581.  struct    Gadget  *gad;
  1582.  
  1583.  extern struct IntuiText    IntegralWin5Text,IntegralWin3Text;
  1584.  
  1585.  SetPointer(FirstWindow,mousemem,16L,16L,0L,0L);
  1586.  
  1587.   n=(xmax-xmin)/xstep;
  1588.  
  1589.   if(n&0x01)  /* first Version was n%2     25.12.1991 */
  1590.     n++;
  1591.  
  1592.    x1=xmin;
  1593.    xs=(xmax-xmin)/(n>>1);   /* double step rate !!   */
  1594.  
  1595.    f=calc(x1);
  1596.    x1+=xs*0.5;              /* the first step to n=1 */
  1597.  
  1598.    for(i=1;i<n;i+=2)
  1599.     {
  1600.       f+=4.0*calc(x1);      /* 4 times all not even parts */
  1601.       x1+=xs;
  1602.     }
  1603.  
  1604.    x1=xmin+xs; /* the step to n=2  */
  1605.  
  1606.    for(i=2;i<n;i+=2)
  1607.     {
  1608.      f+=2.0*calc(x1);       /* 2 times all even parts  */
  1609.      x1+=xs;
  1610.     }
  1611.  
  1612.     f=(f+calc(x1))*(xmax-xmin)/(3.0*n);
  1613.  
  1614.     sprintf(str1,"Xmin= %s  to  Xmax= %s",minx,maxx);
  1615.     printpara((unsigned char *)str2,f);
  1616.     sprintf(str3,"A= %s",str2);
  1617.  
  1618.     IntegralWin5Text.IText=(UBYTE *)str3;
  1619.     IntegralWin3Text.IText=(UBYTE *)str1;
  1620.     IntegralWin5Text.LeftEdge=200-(IntuiTextLength(&IntegralWin5Text)>>1);
  1621.     IntegralWin3Text.LeftEdge=200-(IntuiTextLength(&IntegralWin3Text)>>1);
  1622.                                   /* first version was lenght/2  25.12.1991 */
  1623.  
  1624.     NewOKGadget.ng_LeftEdge      =155;  /* 04.08.1992 */
  1625.     NewOKGadget.ng_TopEdge       =98;
  1626.  
  1627.     gad=CreateContext((struct Gadget **)&nullgadget);
  1628.     gad=CreateGadget((ULONG)BUTTON_KIND,gad,&NewOKGadget,
  1629.            GT_Underscore,(ULONG)'_',TAG_DONE);
  1630.  
  1631.     ThirdNewWindow.FirstGadget=nullgadget;
  1632.  
  1633.     ClearPointer(FirstWindow);
  1634.     MouseCenterWin(&ThirdNewWindow,0,30);
  1635.     if (!(ThirdWindow = OpenWindow(&ThirdNewWindow)))
  1636.        ShowErr(9,FALSE);
  1637.     else
  1638.      {
  1639.       rp4=ThirdWindow->RPort;
  1640.       PrintIText(rp4,&IntegralWin5Text,0L,0L);
  1641.       GT_RefreshWindow(ThirdWindow,NULL);
  1642.        FOREVER
  1643.         {
  1644.          Wait(1L << ThirdWindow->UserPort->mp_SigBit);
  1645.           while(message=(struct IntuiMessage *)GT_GetIMsg(ThirdWindow->UserPort))
  1646.           {
  1647.            MessageClass=message->Class;
  1648.            code=message->Code;
  1649.            qualifier=message->Qualifier;
  1650.            GT_ReplyIMsg(message);
  1651.            switch(MessageClass)
  1652.             {
  1653.                 case IDCMP_REFRESHWINDOW: /*04.08.1992 */
  1654.                   GT_BeginRefresh(ThirdWindow);
  1655.                   PrintIText(rp4,&IntegralWin5Text,0L,0L);
  1656.                   GT_EndRefresh(ThirdWindow,(LONG)TRUE);
  1657.                   break;
  1658.  
  1659.                 case VANILLAKEY:
  1660.                   switch(code)
  1661.                    {
  1662.                      case 'v':
  1663.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  1664.                         break;
  1665.                      case 'O':
  1666.                      case 'o':
  1667.                       GadgetID=7;
  1668.                       break;
  1669.                    }
  1670.                   break;
  1671.  
  1672.                   case GADGETUP:  /* I've only one Gadget  */
  1673.                       GadgetID=7;
  1674.                       break;
  1675.  
  1676.                   default:
  1677.                       break;
  1678.             }
  1679.           }
  1680.         if( GadgetID == 7)
  1681.          break;
  1682.         }
  1683.       CloseWindow(ThirdWindow);
  1684.      }
  1685.  
  1686. if(nullgadget) FreeGadgets(nullgadget);
  1687.  
  1688. }
  1689.  
  1690.  
  1691. UBYTE  WRONGKICKVERSION[]=
  1692. {
  1693.  0,120,25,"Sorry, Kickstart Version greater 37.175 is needed!",0xff,
  1694.  0,184,55,"Press any mousebutton to continue!",0x00
  1695. };
  1696.  
  1697.  
  1698. void Kickerror(void)   /* 28.07.1992 */
  1699. {
  1700.  if (IntuitionBase = (struct IntuitionBase *)
  1701.      OpenLibrary((UBYTE *)"intuition.library", 0L))
  1702.   {
  1703.     DisplayAlert(0L,WRONGKICKVERSION,70L);
  1704.     CloseLibrary((struct Library *)IntuitionBase);
  1705.   }
  1706.  exit(0);
  1707. }
  1708.  
  1709.  
  1710. /*******************************************************************/
  1711. /*                                                                 */
  1712. /*          min_open() will try to open a 640*200 Screen           */
  1713. /*              if OpenScreen() from Open_WINS() fail              */
  1714. /* 13.08.1992                                                      */
  1715. /*******************************************************************/
  1716.  
  1717. void min_open(void)
  1718. {
  1719.  static BOOL recursive=0; /* or check 640*200 */
  1720.  
  1721.  
  1722.    if(AvailMem(MEMF_CHIP|MEMF_LARGEST)<55000L||recursive)
  1723.     {
  1724.       if(ShowErr(18,TRUE))
  1725.        {
  1726.          extSaveConfig();  /* sorry not able to open any screen  */
  1727.          handlesave();
  1728.         }
  1729.        Ende();
  1730.      }
  1731.  
  1732.   recursive=TRUE;
  1733.   scrmode=HIRES_KEY;
  1734.   scrheight=200;
  1735.   scrwidth=640;
  1736.   defscr=0;
  1737.   setscreenprefs();
  1738.   NeueP();
  1739.   Open_WINS();
  1740.   ShowErr(19,FALSE);
  1741.   recursive=FALSE;
  1742.  
  1743. }
  1744.