MODULE PZMapChain EXPORTS Main; (* Last edited on 2001-11-15 18:46:36 by stolfi *) (* 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 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 curve at the origin before mapping. *) reverse : BOOL; (* TRUE to reverse the curve *) END; PROCEDURE Main() = VAR BEGIN WITH o = GetOptions(), m = PZMatrix.Read(FileRd.Open(o.matName & ".matrix")), chData = PZLR3Chain.Read( OpenInput(o.inName), headerOnly := FALSE, centralize := o.center ), a = chData.c^ DO 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 := chData.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. (* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. *)