home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / normalize.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  47 lines

  1. ############################################################################
  2. #
  3. #    File:     normalize.icn
  4. #
  5. #    Subject:  Program to normalize numeric channel
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     January 21, 1999
  10. #
  11. ############################################################################
  12. #
  13. #  This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program reads numbers, one per line, from standard input and
  18. #  writes them out normalized so that the largest is 1.0.
  19. #
  20. ############################################################################
  21. #
  22. #  Links:  numbers
  23. #
  24. ############################################################################
  25.  
  26. link numbers
  27.  
  28. procedure main()
  29.    local numbers, colors, line, i, largest
  30.  
  31.    numbers := []
  32.  
  33.    colors := []
  34.    while line := read() do {
  35.       line ? {
  36.          put(numbers, i := tab(upto(' \t') | 0))
  37.          put(colors, tab(0))
  38.          }
  39.       }
  40.  
  41.    largest := real(max ! numbers)
  42.  
  43.    every i := 1 to *numbers do
  44.       write(numbers[i] / largest, colors[i])
  45.  
  46. end
  47.