MODULE BITCurveToSignal EXPORTS Main; (* Last edited on 1999-12-22 21:12:41 by hcgl *) (* Converts a curve segment into a "shape function" for Fourier analysis. *) (* The program reads an open 2D curve and produces a sequence of samples that can be used as a periodic "signal" in the Hartley-Shannon theorem. *) IMPORT ParseParams, FileRd, FileWr, Wr, Fmt, Process, OSError, Thread, Stdio; IMPORT PZLR3Chain, PZLRChain; FROM PZShape IMPORT Signal; FROM Stdio IMPORT stderr; <* FATAL Wr.Failure, Thread.Alerted, OSError.E *> TYPE Options = RECORD (* Data identification parameters: *) inName: TEXT; (* Input curve file name (without extensions). *) outName: TEXT; (* Output file name (without extensions). *) END; PROCEDURE Main() = BEGIN WITH o = GetOptions(), cd = PZLR3Chain.Read(FileRd.Open(o.inName & ".flc"), headerOnly := FALSE), s = Signal(cd.c^)^, cmt = cd.cmt & SignalComment(), unit = SelectUnit(s) DO PZLRChain.Write( FileWr.Open(o.outName & ".fsh"), cmt, s, stride := 0.0d0, unit := unit ) END; END Main; PROCEDURE SelectUnit(READONLY s: PZLRChain.T): LONGREAL = VAR unit: LONGREAL := 1.0d0/(256.0d0*256.0d0*256.0d0); BEGIN FOR i := 0 TO LAST(s) DO WITH eps = ABS(s[i])/1024.0d0 DO WHILE unit < eps DO unit := 2.0d0*unit END END END; RETURN unit END SelectUnit; PROCEDURE SignalComment(): TEXT = BEGIN RETURN "Converted to signal by BITCurveToSignal" END SignalComment; PROCEDURE GetOptions(): Options = VAR o: Options; BEGIN WITH pp = NEW(ParseParams.T).init(stderr) DO TRY (* Data identification parameters: *) pp.getKeyword("-inName"); o.inName := pp.getNext(); pp.getKeyword("-outName"); o.outName := pp.getNext(); pp.finish(); EXCEPT | ParseParams.Error => Wr.PutText(stderr, "Usage: BITExtractSamples \\\n"); Wr.PutText(stderr, " -inName NAME \\\n"); Wr.PutText(stderr, " -outName NAME \n"); Process.Exit(1); END; END; RETURN o END GetOptions; <*UNUSED*> PROCEDURE FI(x: INTEGER; w: CARDINAL): TEXT = BEGIN RETURN Fmt.Pad(Fmt.Int(x), w, '0') END FI; BEGIN Main() END BITCurveToSignal.