PROCEDURE UniformizeVelocity(c: PZCurve.T): LONG = (* Given a curve "c", this procedure adjusts the nodal times of "c" so as to uniformize its velocity. *) VAR diff, TNew: LONG; BEGIN WITH tOld = c.t^, TOld = c.tPeriod, tNew = NEW(REF LONGS, c.m)^ DO (* Set the time "c.t[j]" to the length from sample "[0]" to sample "[j]": *) VAR s: LONG := 0.0d0; BEGIN FOR j := 0 TO c.m-1 DO tNew[j] := s; s := s + c.s[j] END; TNew := s END; (* Compute variation in spacing: *) diff := 0.0d0; FOR i := 1 TO c.m-1 DO WITH an = tNew[i-1], bn = tNew[i], ao = tOld[i-1], bo = tOld[i] DO diff := MAX(diff, ABS((bn-an)/TNew-(bo-ao)/TOld)); END END; WITH an = tNew[0] + TNew, bn = tNew[c.m-1], ao = tOld[0] + TOld, bo = tOld[c.m-1] DO diff := MAX(diff, ABS((bn-an)/TNew-(bo-ao)/TOld)); END; c.setTimes(tNew, TNew); RETURN diff END END UniformizeVelocity;