home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk373.lzh / Multiplot / source / mplot_src / src.zoo / mp.c_old < prev    next >
Text File  |  1990-08-02  |  20KB  |  616 lines

  1. /***************************************************************************
  2. *                    Copyright (c) 1986, 87, 88 Tim Mooney                 *
  3. *                   also Copyright 1989, 1990 Alan G Baxter                *
  4. *                                                                          *
  5. *   Data input, screen & HPGL output- TM. Interface, Plt: support & con-   *
  6. *   version files- AGB. See docs for distribution restrictions.            *
  7. ***************************************************************************/
  8.  
  9. /***************************************************************************
  10. *   mp.c - PLOT DATA EMBEDDED IN TEXT FILE                                 *
  11. *                                                                          *
  12. *      Mp reads a text file and extracts data from it in a way defined by  *
  13. *   interactive gadget selection or by an automatic script.                *
  14. *   When the data are collected, mp opens a high-res screen, and plots some*
  15. *   or all of the data .  Some of the                                      *
  16. *   details of plotting specifications can be altered in the "Custom Plot" *
  17. *   window callable from menu selection or double click in the main window.*
  18. ****************************************************************************
  19. ***************************************************************************/
  20.  
  21. #include <graphics/display.h>
  22. #include <libraries/dosextens.h>
  23. #include <libraries/diskfont.h>
  24. #include <exec/exec.h>
  25. #include <exec/types.h>
  26. #include <intuition/intuitionbase.h>
  27. #include <graphics/regions.h>
  28. #include <devices/keymap.h>
  29. #include <stdio.h>
  30. #include <workbench/startup.h>
  31. #include <workbench/workbench.h>
  32. #include <workbench/icon.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <graphics/gfxbase.h>
  35. #include <math.h>
  36.  
  37. #define MAIN_MODULE 1
  38.  
  39. #include "struct.h"
  40. #include "plotlim.h"
  41. #include "front.h"
  42.  
  43. struct IntuitionBase *IntuitionBase; /* Pointer aus exec */
  44. struct GfxBase *GfxBase;
  45. struct DiskfontBase  *DiskfontBase;
  46. long IconBase;
  47.  
  48. struct PlotRegion *FullReg;
  49.  
  50. int MAXVERT=512;       /* Globally declared int allows screen size change */
  51. int MAXHORIZ=640;
  52. int CHARWIDTH=8;
  53. int CHARHEIGHT=8;
  54. int LMARGIN=57;  /* CHARWIDTH x 7 */
  55. int RMARGIN=2;
  56. int TMARGIN=8;
  57. int BMARGIN=24;    /* CHARHEIGHT x 3 */
  58. int XMINP=57;      /* LMARGIN */
  59. int YMAXP=504;   /* MAXVERT - TMARGIN */
  60. int YMINP=24;    /* BMARGIN */
  61. int XMAXP=638;   /* (MAXHORIZ-RMARGIN) */
  62.  
  63. extern short firstcall;
  64. extern struct Screen *screen;
  65. extern struct NewScreen newscreen;
  66. extern struct NewWindow newwindow;
  67. extern struct MenuItem ErrorBars;
  68. extern struct TextBox *ExtraText;
  69.  
  70. #define QUIT 0
  71. #define GO 1
  72. #define OFF 0
  73. #define ON 1
  74.  
  75. int QuitFrontFlag;  /* Quit flag for Front Window requester */
  76. int KEEP_GOING=1;      /* Quit flag for the whole program which all but */
  77.                        /* closes the screen when "New" is selected.     */
  78.  
  79. FFP xtic[MAXTICS],ytic[MAXTICS];
  80. short xticp[MAXTICS],yticp[MAXTICS];
  81. char filename[150], progname[150];
  82.  
  83. struct RastPort *p;
  84. struct Pict *Pict;
  85. int xcol=1, ycol=2, ecol=0;
  86.  
  87. extern struct ViewPort *vp;
  88. char StartDir[150];
  89.  
  90. main(argc,argv)
  91. int argc;
  92. union {
  93.    char **args;
  94.    struct WBStartup *msg;
  95. } argv;
  96. {
  97.    struct WBArg *arg;
  98.    USHORT AUTO=FALSE, Overscan=ON; /* Overscan flag can be turned off at start */
  99.    FILE *fp;
  100.    char **ToolArray;
  101.    char *Value;
  102.    struct IntuiMessage  *p_message;         /* pointer to message */
  103.    struct DiskObject *diskobj;
  104.    void ProcMes(), sexit(), OpenLibraries(), GetBestScreen(), BailOut(), ResetWindow();
  105.    USHORT RunAutoScript();
  106.  
  107.  
  108.    filename[0] = 0;
  109.    OpenLibraries();
  110.    /* FFPLARGE = 1.0e10; FFPSMALL = 1.0e-10; */
  111.  
  112.    /*** PARSE ARGS ***/
  113.    if (argc != 0) { /* called from CLI */
  114.       stcgfp(StartDir,argv.args[0]);
  115.       if (argc>1)   {
  116.          if (argv.args[argc-1][0] == '?') {
  117.           printf("usage: MultiPlot [-[O][B#]] [filename]\n");
  118.           exit(0);
  119.          }
  120.          if (argv.args[argc-1][0] != '-') {
  121.            strcpy(filename,argv.args[argc-1]);
  122.            strcpy(Gadget4SIBuff,filename);
  123.            AUTO=TRUE;
  124.          }
  125.          if (argv.args[1][0] == '-') {
  126.             if ((argv.args[1][1] == 'O')||(argv.args[1][1]=='o')) { Overscan=OFF; }
  127.             if ((argv.args[1][1] == 'B')||(argv.args[1][1]=='b')) {
  128.                if (argv.args[1][2] =='1')  {newscreen.Depth=1;}
  129.                else if (argv.args[1][2] =='2')  {newscreen.Depth=2;}
  130.                else if (argv.args[1][2] =='3')  {newscreen.Depth=3;}
  131.                else {newscreen.Depth=4;}
  132.                if ((argv.args[1][3] == 'O')||(argv.args[1][3]=='o')||(argv.args[1][2] == 'O')||(argv.args[1][2]=='o'))
  133.                   { Overscan=OFF; }
  134.             }
  135.          }
  136.  
  137.       }
  138.     }
  139.  
  140.    else { /* called from workbench */
  141.       arg = argv.msg->sm_ArgList; /* point to command - find where multiplot lives */
  142.       if (arg->wa_Lock != NULL) {
  143.          getpath(arg->wa_Lock,StartDir);
  144.          if (isdev(StartDir)) strcat(StartDir,":");
  145.       }
  146.       else stcgfp(StartDir,arg->wa_Name);
  147.       arg++;
  148.       if (argv.msg->sm_NumArgs > 1) {         /* find where data file lives */
  149.          AUTO=TRUE;
  150.          getpath(arg->wa_Lock,Gadget4SIBuff);
  151.          if (isdev(Gadget4SIBuff)) strcat(Gadget4SIBuff,":");
  152.          strmfp(Gadget4SIBuff,Gadget4SIBuff,arg->wa_Name);
  153.       }
  154.       strmfp(progname,StartDir,"multiplot");
  155.       if (diskobj=GetDiskObject(progname))
  156.         {
  157.            ToolArray=diskobj->do_ToolTypes;
  158.            Value=FindToolType(ToolArray,"OVERSCAN");
  159.            if (MatchToolValue(Value,"OFF")) {Overscan=OFF;}
  160.            Value=FindToolType(ToolArray,"BITPLANES");
  161.            if (MatchToolValue(Value,"1")) {newscreen.Depth=1;}
  162.            else if (MatchToolValue(Value,"2")) {newscreen.Depth=2;}
  163.            else if (MatchToolValue(Value,"3")) {newscreen.Depth=3;}
  164.            else  {newscreen.Depth=4;}
  165.            FreeDiskObject(diskobj);
  166.         }
  167.    }
  168.  
  169.    GetBestScreen(Overscan);
  170.  
  171.    while (KEEP_GOING)
  172.    {
  173.      ResetWindow();
  174.      if (AUTO) AUTO=RunAutoScript();
  175.      if (!AUTO)
  176.         {
  177.           NewFrontWindow.Screen = screen;
  178.           NewFrontWindow.Title ="                Data Selection Window            ";
  179.           NewFrontWindow.FirstGadget = &Gadget6;
  180.           if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  181.            {
  182.               ErrorAlert(0);
  183.               CloseScreen(screen);
  184.               sexit(FALSE);
  185.            }
  186.           ActivateGadget(&Gadget4,FrontWindow,0);
  187.           p = FrontWindow->RPort;
  188.           PrintIText(p,&IText2,0,0);
  189.           QuitFrontFlag=GO;     /* Reset flag in case not first time ***/
  190.           firstcall=TRUE;
  191.  
  192.           while (QuitFrontFlag !=QUIT)
  193.            {
  194.              Wait(1l<<FrontWindow->UserPort->mp_SigBit);        /* wait for a message */
  195.              while (p_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
  196.                ProcMes(p_message);
  197.            }
  198.  
  199.           if (!KEEP_GOING)   /*  STOP GADGET SELECTED FROM FRONT WINDOW */
  200.            {
  201.               CloseWindow(FrontWindow);
  202.               CloseScreen(screen);
  203.               sexit(FALSE);
  204.            }
  205.  
  206.           /*** GIVE USER SOMETHING TO LOOK AT ***/
  207.           SetPointer(FrontWindow,WaitSprite,26,14,-4,-4);
  208.           SetWindowTitles(FrontWindow,-1,"    Loading data from file...  ");
  209.  
  210.           /*** SALVAGE USER REQUESTS FROM GADGET FIELDS ***/
  211.           strcpy(filename,Gadget4SIBuff);
  212.           xcol=Gadget1SInfo.LongInt;
  213.           ycol=Gadget2SInfo.LongInt;
  214.           ecol=Gadget3SInfo.LongInt;
  215.  
  216.         }
  217.  
  218.      /*** OPEN FILE ***/
  219.      fp = fopen(filename,"r");
  220.      if (!fp) {
  221.         Message("     Can't open file        ");
  222.         CloseWindow(FrontWindow);
  223.         CloseScreen(screen);
  224.         sexit(FALSE);
  225.      }
  226.      AUTO=FALSE;     /* So we get the file selector if user wants to open new file */
  227.  
  228.      /*** ALLOCATE/INITIALIZE MEMORY FOR STRUCT PICT ***/
  229.      if (!(Pict = (struct Pict *)AllocMem(sizeof(struct Pict),MEMF_CLEAR)))
  230.        {ErrorAlert(0); CloseScreen(screen); sexit(FALSE);}
  231.  
  232.      if ((!(Pict->Tics = (struct Tics *)AllocMem(sizeof(struct Tics),MEMF_CLEAR)))||
  233.         (!(Pict->CurrReg = (struct PlotRegion *)AllocMem(sizeof(struct PlotRegion),MEMF_CLEAR)))||
  234.         (!(Pict->NewReg = (struct PlotRegion *)AllocMem(sizeof(struct PlotRegion),MEMF_CLEAR)))||
  235.         (!(Pict->Title = (struct TextBox *)AllocMem(sizeof(struct TextBox),MEMF_CLEAR)))||
  236.         (!(Pict->XLabel = (struct TextBox *)AllocMem(sizeof(struct TextBox),MEMF_CLEAR)))||
  237.         (!(Pict->YLabel = (struct TextBox *)AllocMem(sizeof(struct TextBox),MEMF_CLEAR))))
  238.            {(void) fclose(fp); BailOut(Pict);}
  239.  
  240.      Pict->Tics->x = xtic;Pict->Tics->y = ytic;
  241.      Pict->Tics->xp = xticp;Pict->Tics->yp = yticp;
  242.      Pict->XRegionLock = Pict->YRegionLock = FALSE;
  243.      Pict->Axes = TRUE;
  244.      Pict->RMargin=TRUE;
  245.      Pict->Plot = NULL;
  246.      Pict->ErrBar = (ecol != 0);
  247.  
  248.      /*** GET DATA FROM FILE ***/
  249.      GetDat(fp, xcol, ycol, ecol, Pict);
  250.      (void) fclose(fp);
  251.  
  252.      /*** SORT OUT PLOT SIZE FOR SCALING LATER ****/
  253.      if (!(FullReg= (struct PlotRegion *)AllocMem(sizeof(struct PlotRegion),MEMF_CLEAR)))
  254.        BailOut(Pict);
  255.      GetPlotLimits(Pict,FullReg);
  256.  
  257.      /*** PREPARE MENU STRIP FOR PLOTTING WINDOW ***/
  258.      if (Pict->ErrBar) {if (ErrorBars.Flags & ITEMENABLED); else ErrorBars.Flags |= ITEMENABLED;}
  259.      else {if (ErrorBars.Flags & ITEMENABLED) ErrorBars.Flags &= ~ITEMENABLED;}
  260.  
  261.      /**** GET RID OF FRONT WINDOW ***/
  262.      SetWindowTitles(FrontWindow,-1,newscreen.DefaultTitle);
  263.      CloseWindow(FrontWindow);
  264.      ClearPointer(FrontWindow);
  265.      if (NewFrontWindow.Flags & BORDERLESS) NewFrontWindow.Flags &= ~BORDERLESS;
  266.  
  267.      /*** PLOT DATA ***/
  268.      plot(Pict);
  269.  
  270.      /*** DEALLOCATE MEMORY ***/
  271.      FreeMemory(Pict);
  272.    }
  273.    /*** GO HOME ***/
  274.    CloseScreen(screen);
  275.    sexit(TRUE);
  276. }
  277.  
  278.  
  279.  
  280. int isdev(string)
  281. char *string;
  282. {
  283. while ((*string!=':') && (*string!='\0')) string++;
  284. if (*string==':') return(FALSE);
  285. else return(TRUE);
  286. }
  287.  
  288.  
  289.  
  290.  
  291. void ProcMes(p_message)
  292. struct IntuiMessage *p_message;
  293. {
  294. ULONG MesClass;        /*     Fields for storing      */
  295. USHORT MesCode;        /*     intuimessage data       */
  296. APTR Pointer;          /*                             */
  297. int HandleEvent();
  298.  
  299.    MesClass = p_message->Class;             /* Store values */
  300.    MesCode = p_message->Code;
  301.    Pointer = p_message->IAddress;
  302.    ReplyMsg(p_message);                     /* Reply to message */
  303.    HandleEvent(MesClass,MesCode,Pointer);
  304. }
  305.  
  306. int HandleEvent(MesClass,MesCode,Pointer)
  307. ULONG MesClass;        /*     Fields for storing      */
  308. USHORT MesCode;        /*     intuimessage data       */
  309. APTR Pointer;          /*                             */
  310. {
  311. struct Process  *OurTask;
  312. struct Window   *old_pr_WindowPtr;
  313. static char drive[150], path[100], node[30], extn[20];
  314. short len;
  315.  
  316.   if ( MesClass == GADGETDOWN)
  317.     {
  318.       if (Pointer == (APTR)&Gadget6) FindData();
  319.       if (Pointer == (APTR)&XDown)
  320.          {
  321.             RemoveGadget(FrontWindow,&Gadget1);
  322.             if (Gadget1SInfo.LongInt<1) {Message(" Column number must be +ve ");}
  323.             else Gadget1SInfo.LongInt=Gadget1SInfo.LongInt-1;
  324.             stci_d(Gadget1SIBuff,Gadget1SInfo.LongInt);
  325.             AddGadget(FrontWindow,&Gadget1,-1L);
  326.             RefreshGadgets(&Gadget1,FrontWindow,NULL);
  327.          }
  328.       if (Pointer == (APTR)&XUp)
  329.          {
  330.             RemoveGadget(FrontWindow,&Gadget1);
  331.             Gadget1SInfo.LongInt=Gadget1SInfo.LongInt+1;
  332.             stci_d(Gadget1SIBuff,Gadget1SInfo.LongInt);
  333.             AddGadget(FrontWindow,&Gadget1,-1L);
  334.             RefreshGadgets(&Gadget1,FrontWindow,NULL);
  335.          }
  336.       if (Pointer == (APTR)&YDown)
  337.          {
  338.             RemoveGadget(FrontWindow,&Gadget2);
  339.             if (Gadget2SInfo.LongInt<2) {Message("   Y Column must exist  ");}
  340.             else Gadget2SInfo.LongInt=Gadget2SInfo.LongInt-1;
  341.             stci_d(Gadget2SIBuff,Gadget2SInfo.LongInt);
  342.             AddGadget(FrontWindow,&Gadget2,-1L);
  343.             RefreshGadgets(&Gadget2,FrontWindow,NULL);
  344.          }
  345.       if (Pointer == (APTR)&YUp)
  346.          {
  347.             RemoveGadget(FrontWindow,&Gadget2);
  348.             Gadget2SInfo.LongInt=Gadget2SInfo.LongInt+1;
  349.             stci_d(Gadget2SIBuff,Gadget2SInfo.LongInt);
  350.             AddGadget(FrontWindow,&Gadget2,-1L);
  351.             RefreshGadgets(&Gadget2,FrontWindow,NULL);
  352.          }
  353.       if (Pointer == (APTR)&EDown)
  354.          {
  355.             RemoveGadget(FrontWindow,&Gadget3);
  356.             if (Gadget3SInfo.LongInt<1) {Message(" Column number must be +ve ");}
  357.             else Gadget3SInfo.LongInt=Gadget3SInfo.LongInt-1;
  358.             stci_d(Gadget3SIBuff,Gadget3SInfo.LongInt);
  359.             AddGadget(FrontWindow,&Gadget3,-1L);
  360.             RefreshGadgets(&Gadget3,FrontWindow,NULL);
  361.          }
  362.       if (Pointer == (APTR)&EUp)
  363.          {
  364.             RemoveGadget(FrontWindow,&Gadget3);
  365.             Gadget3SInfo.LongInt=Gadget3SInfo.LongInt+1;
  366.             stci_d(Gadget3SIBuff,Gadget3SInfo.LongInt);
  367.             AddGadget(FrontWindow,&Gadget3,-1L);
  368.             RefreshGadgets(&Gadget3,FrontWindow,NULL);
  369.          }
  370.  
  371.       if (Pointer == (APTR)&Gadget5a)
  372.          {
  373.           KEEP_GOING=FALSE;
  374.           QuitFrontFlag = QUIT;
  375.           return(-1);
  376.          }
  377.       if (Pointer == (APTR)&Gadget5)
  378.          {
  379.           strsfn(Gadget4SIBuff,drive,path,node,extn);
  380.           strcat(drive,path);
  381.           strmfe(node,node,extn);
  382.  
  383.           OurTask = (struct Process *)FindTask(0L);
  384.           old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  385.           OurTask->pr_WindowPtr = (APTR)FrontWindow;
  386.           if (get_fname(FrontWindow,screen,"Select File to Open...",node,drive)==NULL)
  387.                {
  388.                   OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  389.                   return(0);
  390.                }
  391.            OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  392.            RemoveGadget(FrontWindow,&Gadget4);
  393.            strmfp(Gadget4SIBuff,drive,node);
  394.            len =strlen(Gadget4SIBuff);
  395.            Gadget4SInfo.BufferPos=len;
  396.            Gadget4SInfo.DispPos=len-29;
  397.            AddGadget(FrontWindow,&Gadget4,-1L);
  398.            RefreshGadgets(&Gadget4,FrontWindow,NULL);
  399.            ActivateGadget(&Gadget4,FrontWindow,0);
  400.           }
  401.        else ;
  402.     }
  403.   if ( MesClass == RAWKEY) {
  404.       if (MesCode ==196) FindData();   /* RETURN key RELEASED */
  405.       else if (MesCode ==69) { KEEP_GOING=FALSE; QuitFrontFlag = QUIT; return(-1); } /* ESCAPE key PRESSED */
  406.   }
  407.   return(1);
  408. }
  409.  
  410.  
  411. FindData()
  412. {
  413. FILE *fp;
  414.  
  415.    if (fp = fopen(Gadget4SIBuff,"r") )
  416.      {
  417.        SetPointer(FrontWindow,WaitSprite,26,14,-4,-4);
  418.        SetWindowTitles(FrontWindow,-1,"    Checking file... ");
  419.        if (CheckDat(fp,Gadget1SInfo.LongInt,Gadget2SInfo.LongInt,Gadget3SInfo.LongInt))
  420.           {
  421.             QuitFrontFlag = QUIT;
  422.           }
  423.        fclose(fp);
  424.        ClearPointer(FrontWindow);
  425.      }
  426.    else
  427.      {
  428.        SetWindowTitles(FrontWindow,-1,newscreen.DefaultTitle);
  429.        Message("     Can't open file        ");
  430.      }
  431.    return(0);
  432. }
  433.  
  434.  
  435. void OpenLibraries()
  436. {
  437.    /*** OPEN LIBRARIES ***/
  438.    if (!(IconBase = OpenLibrary("icon.library", 0)))
  439.       { ErrorAlert(1); sexit(FALSE); }
  440.    DiskfontBase = (struct DiskfontBase *) OpenLibrary("diskfont.library",0);
  441.    if( DiskfontBase == NULL )
  442.       { ErrorAlert(2); sexit(FALSE); }
  443.    GfxBase=NULL;
  444.    GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",33);
  445.    if(GfxBase == NULL)
  446.       { ErrorAlert(3); sexit (FALSE); }
  447. }
  448.  
  449. void ResetWindow()
  450. {
  451.    TMARGIN=CHARHEIGHT;
  452.    BMARGIN= (CHARHEIGHT * 3);
  453.    YMINP= BMARGIN;
  454.    YMAXP=MAXVERT - TMARGIN;
  455.    XMAXP=MAXHORIZ-RMARGIN;
  456.    LMARGIN=(7 * CHARWIDTH);
  457.    XMINP=LMARGIN;
  458. }
  459.  
  460. void sexit(Err)
  461. int Err;
  462. {
  463. if (IconBase) CloseLibrary(IconBase);
  464. if (IntuitionBase) CloseLibrary(IntuitionBase);
  465. if (GfxBase) CloseLibrary(GfxBase);
  466. if (DiskfontBase) CloseLibrary(DiskfontBase);
  467. exit(Err);
  468. }
  469.  
  470.  
  471. void BailOut(Pict)
  472. {
  473.    ErrorAlert(0);
  474.    FreeMemory(Pict);
  475.    CloseScreen(screen);
  476.    sexit(FALSE);
  477. }
  478.  
  479.  
  480. void GetBestScreen(Overscan)
  481. USHORT Overscan;
  482. {
  483. int x=0,y=0, OldLib=FALSE;
  484.  
  485.    /* SORT OUT SCREEN SIZING -- NOT ALL THAT SIMPLE!! */
  486.    IntuitionBase=NULL;
  487.    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",33);  /* PAL Revision */
  488.    if (IntuitionBase == NULL) {
  489.       OldLib=TRUE;
  490.       IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  491.       if(IntuitionBase == NULL) {
  492.           ErrorAlert(4);
  493.           sexit(FALSE);
  494.       }
  495.    }
  496.    if ( (OldLib==FALSE) && ((GfxBase->DisplayFlags) & PAL ) ) {
  497.       if ( ScreenSize(&x,&y) && (Overscan==ON) && ( (x<=705) && ((y<=281)||((y>=512)&&(y<=562)))))
  498.         {
  499.            if (y<512) y*=2; /* if WB is not interlace, double resolution */
  500.            MAXHORIZ=newscreen.Width=newwindow.Width=x;
  501.            MAXVERT=newscreen.Height=newwindow.Height=y;
  502.         }
  503.       else
  504.         {
  505.            MAXHORIZ=newscreen.Width=newwindow.Width=640;
  506.            MAXVERT=newscreen.Height=newwindow.Height=512;
  507.         }
  508.    }
  509.    else {  /* US or old libraries */
  510.       if ( ScreenSize(&x,&y) && (Overscan==ON) && ( (x<=705) && ((y<=225)||((y>=400)&&(y<=450)))))
  511.         {
  512.            if (y<400) y*=2; /* if WB is not interlace, double resolution */
  513.            MAXHORIZ=newscreen.Width=newwindow.Width=x;
  514.            MAXVERT=newscreen.Height=newwindow.Height=y;
  515.         }
  516.       else
  517.         {
  518.            MAXHORIZ=newscreen.Width=newwindow.Width=640;
  519.            MAXVERT=newscreen.Height=newwindow.Height=400;
  520.         }
  521.    }
  522.  
  523.    if (!(screen = (struct Screen *)OpenScreen(&newscreen)))
  524.       {
  525.          ErrorAlert(0);
  526.          sexit(FALSE);
  527.       }
  528.    vp = &screen->ViewPort;
  529.    InitColours();
  530. }
  531.  
  532. USHORT RunAutoScript()
  533. {
  534. USHORT temp, AUTO=FALSE;
  535. FILE *fp;
  536. char  cbuf[100], *cb;
  537.  
  538.    NewFrontWindow.Screen = screen;
  539.    NewFrontWindow.Title =NULL;
  540.    NewFrontWindow.FirstGadget =NULL;
  541.    if (NewFrontWindow.Flags & BORDERLESS);
  542.    else NewFrontWindow.Flags |= BORDERLESS;
  543.    strcpy(filename,Gadget4SIBuff);
  544.  
  545.    if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  546.       { ErrorAlert(0); CloseScreen(screen); sexit(FALSE); }
  547.  
  548.    fp = fopen(filename,"r");
  549.    if (!fp) {
  550.       Message("     Can't open file        ");
  551.       CloseScreen(screen);
  552.       sexit(FALSE);
  553.    }
  554.    /*** CHECK FILE TO SEE IF MULTIPLOT WROTE IT ***/
  555.    while ((AUTO==FALSE)&&(cb = fgets(cbuf,100,fp)))
  556.       {
  557.         if (same(cb,"*AUTOSCRIPT*",12))
  558.            {
  559.               AUTO=TRUE;
  560.               sscanf(cb,"%*s %hd",&temp);
  561.               if (temp) ecol=3;
  562.            }
  563.       }
  564.    fclose(fp);
  565.  
  566.    if (!AUTO)
  567.      {
  568.         CloseWindow(FrontWindow);  /* Close dud window as need file req anyway */
  569.         if (NewFrontWindow.Flags & BORDERLESS) NewFrontWindow.Flags &= ~BORDERLESS;
  570.      }
  571.    else
  572.     {
  573.      /*** GIVE USER SOMETHING TO LOOK AT ***/
  574.        SetPointer(FrontWindow,WaitSprite,26,14,-4,-4);
  575.        SetWindowTitles(FrontWindow,-1,"    Loading data from file...  ");
  576.     }
  577.   return(AUTO);
  578. }
  579.  
  580.  
  581.  
  582. ScreenSize(x,y)
  583. int *x;
  584. int *y;
  585. {
  586. struct Screen *WBScreen;
  587. int result;
  588.  
  589.    WBScreen = (struct Screen *)AllocMem(sizeof(struct Screen),MEMF_CLEAR);
  590.    result = GetScreenData(WBScreen,sizeof(struct Screen),WBENCHSCREEN,NULL);
  591.    *x=WBScreen->Width;
  592.    *y=WBScreen->Height;
  593.    /* printf("%d %d\n",*x,*y); */
  594.    FreeMem(WBScreen,sizeof(struct Screen));
  595.    return(result);
  596. }
  597.  
  598. FreeMemory(Pict)
  599. struct Pict *Pict;
  600. {
  601.   if (Pict->NewReg) FreeMem(Pict->NewReg,sizeof(struct PlotRegion));
  602.   if (Pict->CurrReg) FreeMem(Pict->CurrReg,sizeof(struct PlotRegion));
  603.   if (Pict->Tics) FreeMem(Pict->Tics,sizeof(struct Tics));
  604.   if (Pict->Title) FreeMem(Pict->Title,sizeof(struct TextBox));
  605.   if (Pict->XLabel) FreeMem(Pict->XLabel,sizeof(struct TextBox));
  606.   if (Pict->YLabel) FreeMem(Pict->YLabel,sizeof(struct TextBox));
  607.   if (FullReg) FreeMem(FullReg,sizeof(struct PlotRegion));
  608.   if (Pict) FreeMem(Pict,sizeof(struct Pict));
  609.   FreeStructPlot();
  610.   return(0);
  611. }
  612.  
  613.  
  614.  
  615.  
  616.