perm filename PLOT.SAI[HAK,ROB] blob sn#455035 filedate 1979-06-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00007 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	begin "PLOT"
C00005 00003	α requires and external definitions
C00007 00004	α declarations
C00008 00005	α local procedures
C00012 00006	α the Program
C00015 00007	α the end
C00016 ENDMK
C⊗;
begin "PLOT"

  comment 
    This program takes one of Leland Smith's plot (.PLT) files, and
    plots them on the CalComp plotter.  It writes out a little (.SAV) file
    every few vectors on how far it has gotten.  If the system crashes,
    the pen can be repositioned at the origin, and the .SAV file is
    read in to pick up where things.  When the plot is succefully finished,
    the .SAV file is deleted.
  ;

  REQUIRE "{}<>" DELIMITERS;

  DEFINE SP={" "},
    CR={('15&"")},
    LF={('12&"")},
    ↓={('15&'12)},
    TAB={('11&"")},
    FF={('14&"")},
    QT={""""},
    ALT={('175&"")},
    VT={('13&"")},
    BS={('177&"")};

  DEFINE α = {COMMENT},
    ⊂ = {BEGIN},
    ⊃ = {END};

  DEFINE $DBUG = TRUE;
  DEFINE DBUGPRINT(str) = {IF $DBUG THEN PRINT(str)};
  DEFINE THROUGH = {STEP 1 UNTIL};
  DEFINE DOWNTO = {STEP -1 UNTIL};
  DEFINE DOWN = {STEP -1 UNTIL 0};

  DEFINE PI = {3.14159265358979};

  DEFINE AsciiMode = {('0)};
  DEFINE ImageMode = {('10)};

  DEFINE InDev = {"DSK"};
  DEFINE OuDev = {"DSK"};
  DEFINE PltIBuffs = {('20)};
  DEFINE PltOBuffs = {('00)};
  DEFINE SavFName = {"P.SAV"};
  DEFINE SavIBuffs = {('02)};
  DEFINE SavOBuffs = {('02)};

α requires and external definitions;

  α source in IO.SAI[LIB,KS];

  require "IO.REL[LIB,KS]" load_module;

  external integer COLONTBL,FFLFTBL,SPTABTBL,TOKENTBL;

  external record_class $file(
	  string DEVICE,NAME;
	  integer SIXNAME,SIXEXTEN,SIXPPN;
	  integer CHANNEL,MODE,IBUF,OBUF,COUNT,BRCHAR,EOF;
	  integer LINNUM,PAGNUM,SOSNUM;
	  integer array INFO);

  external record_pointer($file) procedure OPENUP(
	  string FILNAM;
	  integer MODE,IBUF,OBUF);

  external record_pointer($file) procedure GETFILE(
	  string PROMPT;
	  integer MODE,I,O;
	  string DEFDEV,DEFNAME);

  external procedure SkipE(
	  record_pointer($file) InStream;
	  reference string BufChars);

  external integer procedure NextChar(
	  record_pointer($file) InStream;
	  reference string BufChars);

α declarations;

  record_pointer($file) PLTFILE, SAVFILE;
  string LINE, CHAR;
  string PltName,PltDone;
  integer NVects;
  integer brk;

α local procedures;

  PROCEDURE GetSaveInfo(
    REFERENCE STRING PlotName, PlotDone);
    ⊂ "Update the Save File"
      PltName ← INPUT($file:channel[SavFile],FFLFTBL);
      PltDone ← INPUT($file:channel[SavFile],FFLFTBL);
      USETO($file:channel[SavFile],1);	α Point at head of file;
    ⊃ "Update the Save File";


  PROCEDURE UpdSaveInfo(
    STRING PlotName, PlotDone);
    α Must enter with output pointer at head of file!
      Does the output, and a USETO, which will re-position the output pointer,
      and force output to be written...;
    ⊂ "Update the Save File"
      OUT($file:channel[SavFile],PlotName&↓&PlotDone&↓);
      USETO($file:channel[SavFile],1);	α Point at head of file;
    ⊃ "Update the Save File";

  PROCEDURE MakeVect(
    INTEGER NextX,NextY,Penup);
    ⊂ "Plot a vector"
      PRINT("Pen",IF Penup THEN "up" ELSE "dn",TAB,NextX,TAB,NextY,↓);
    ⊃ "Plot a vector";

  INTEGER PROCEDURE PlotOneBlock;
    ⊂ "Plot one block of vectors"
      INTEGER NVects, i;

      NVects ← WORDIN($file:channel[PltFile]);
      FOR i ← 1 THROUGH NVects-1 DO
	⊂ "Plot each vector"
	  INTEGER RawWord, NextX, NextY, Penup;

	  RawWord ← WORDIN($file:channel[PltFile]);
	  NextX ← RawWord LSH 18;	α This conversion is clearly wrong...;
	  NextY ← RawWord LAND '177;
	  Penup ← RawWord LAND '7;
	  MakeVect(NextX,NextY,Penup);
	⊃ "Plot each vector";
      RETURN(NVects);
    ⊃ "Plot one block of vectors";
      
  PROCEDURE SkipVects(
    INTEGER NVects);
    ⊂ "Skip over some vectors"
    ⊃ "Skip over some vectors";

  PROCEDURE PlotAllBlocks(
    INTEGER TotVects);
    ⊂ "Plot all the vectors"
      INTEGER NVects;

      SkipVects(TotVects);
      DO
	⊂
          Nvects ← PlotOneBlock;
	  TotVects ← TotVects + NVects;  α Keep track of how many we've done;
	  UpdSaveInfo($file:device[PltFile]&":"&$file:name[PltFile],CVS(TotVects));
	⊃
        UNTIL NVects ≠ 256;
    ⊃ "Plot all the vectors";
α the Program;

  SavFile ← OPENUP(SavFName,AsciiMode,SavIBuffs,SavOBuffs);
  IF $file:eof[SavFile]
    THEN
      ⊂ "This is a new plot"
	PltFile ← GetFile("Input plot file:",ImageMode, PltIBuffs, PltOBuffs, "DSK",".PLT");
	SavFile ← OPENUP(SavFName,AsciiMode,0,SavOBuffs);
	UpdSaveInfo($file:device[PltFile]&":"&$file:name[PltFile],"0");
        RELEASE($file:channel[SavFile]);
	SavFile ← OPENUP(SavFName,AsciiMode,SavIBuffs,SavOBuffs);
        PRINT("I have just created a .SAV file (I hope)..."); INCHWL;
      ⊃ "This is a new plot"
    ELSE
      ⊂ "Pick up where we left off"
	GetSaveInfo(PltName, PltDone);
	NVects ← INTSCAN(PltDone,brk);
	PRINT("Using ",Pltname," at vector #",NVects,↓);
	PltFile ← OPENUP(PltName,ImageMode,PltIBuffs,PltOBuffs);
	IF $file:eof[PltFile]
	  THEN
	    ⊂ "Can't find the old .PLT file"
	      print("Can't find ",PltName,".  I quit!",↓);
	    ⊃ "Can't find the old .PLT file"
	  ELSE
	    ⊂ "Got the old .PLT file"
	      PRINT("Please position pen at origin and type (return)..."); INCHWL;
	      PRINT("Now I am doing 30 vectors...",↓);  NVects ← NVects + 30;
	      UpdSaveInfo(PltName,CVS(NVects));
	      PRINT("Now I have done 30 vectors..."); INCHWL;
	    ⊃ "Got the old .PLT file";
      ⊃ "Pick up where we left off";
α the end;

end "PLOT";