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