MODULE PZMapChain EXPORTS Main; (* Last edited on 1999-12-31 06:30:33 by hcgl *) (* Applies a geometric transformation to a curve *) (* Reads a PZLR3Chain.T from standard input, applies a 4x4 matrix to it, writes the resulting PZLR3Chain.T to standard output *) IMPORT ParseParams, Text, Process, FileRd, Rd, Wr, FileWr, OSError, Thread, Stdio; IMPORT LR3; IMPORT PZLR3Chain, PZMatrix; FROM Stdio IMPORT stderr, stdin, stdout; FROM PZTypes IMPORT BOOL; <* FATAL Wr.Failure, Thread.Alerted, OSError.E *> TYPE Options = RECORD inName: TEXT; (* Input file name without extension, OR "-" *) matName: TEXT; (* Matrix file name without extension. *) outName: TEXT; (* Output file name without extension, OR "-" *) center: BOOL; (* TRUE to center the chain at the origin before mapping. *) reverse : BOOL; (* TRUE to reverse the chain *) END; PROCEDURE Main() = VAR BEGIN WITH o = GetOptions(), m = PZMatrix.Read(FileRd.Open(o.matName & ".matrix")), ra = PZLR3Chain.Read(OpenInput(o.inName), headerOnly := FALSE), a = ra.c^ DO IF o.center THEN WITH b = PZLR3Chain.Barycenter(a) DO FOR i := 0 TO LAST(a) DO a[i] := LR3.Sub(a[i], b) END END END; IF o.reverse THEN PZLR3Chain.Reverse(a) END; PZMatrix.Write(stderr, m); WITH b = PZLR3Chain.Map(a ,m)^ DO PZLR3Chain.Write( wr := OpenOutput(o.outName), cmt := " ", c := b, unit := ra.unit ); END; END END Main; PROCEDURE GetOptions(): Options = VAR o: Options; BEGIN WITH pp = NEW(ParseParams.T).init(stderr) DO TRY IF pp.keywordPresent("-inName") THEN o.inName := pp.getNext(); ELSE o.inName := "" END; o.center := pp.keywordPresent("-center"); pp.getKeyword("-matName"); o.matName := pp.getNext(); o.reverse := pp.keywordPresent("-reverse"); IF pp.keywordPresent("-outName") THEN o.outName := pp.getNext(); ELSE o.outName := "" END; pp.finish(); EXCEPT | ParseParams.Error => Wr.PutText(stderr, "Usage: PZMapChain \\\n"); Wr.PutText(stderr, " [ -inName ] \\\n"); Wr.PutText(stderr, " [ -center ] \\\n"); Wr.PutText(stderr, " [ -reverse ] \\\n"); Wr.PutText(stderr, " -matName \\\n"); Wr.PutText(stderr, " [ -outName ] \n"); Process.Exit(1); END; END; RETURN o END GetOptions; PROCEDURE OpenInput(file: TEXT): Rd.T = BEGIN IF Text.Empty(file) THEN RETURN stdin ELSE RETURN FileRd.Open(file & ".flc") END END OpenInput; PROCEDURE OpenOutput(file: TEXT): Wr.T = BEGIN IF Text.Empty(file) THEN RETURN stdout ELSE RETURN FileWr.Open(file & ".flc") END END OpenOutput; BEGIN Main() END PZMapChain.