summaryrefslogtreecommitdiff
path: root/ipl/procs/readcpt.icn
blob: 2606be907b22b762578d8b8e6596e1d55d16fa7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
############################################################################
#
#	File:     readcpt.icn
#
#	Subject:  Procedure to read produce "carpet" from file
#
#	Author:   Ralph E. Griswold
#
#	Date:     August 7, 1997
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This procedure reads a "carpet" file and returns a corresponding matrix.
#
############################################################################
#
#  Links:  matrix
#
############################################################################
#
#  See also:  writecpt.icn 
#
############################################################################

link matrix

procedure read_cpt(input)	#: convert numerical carpet to matrix
   local carpet, width, height, i, j, line

   read(input) ? {
      ="width=" &
      width := integer(tab(many(&digits))) &
      =" height=" &
      height := integer(tab(many(&digits)))
      } | stop("*** invalid carpet file")

   carpet := create_matrix(height, width)

   every j := 1 to height do {
      line := read(input) | stop("*** short carpet data")
      i := 0
      line ? {
         while carpet[j, i +:= 1] := tab(upto(' ')) do
            move(1) | stop("*** narrow carpet data")
         }
      }

   return carpet

end