1      PROGRAM PACK
2C-----------------------------------------------------------------------
3C Convert unpacked (ASCII) representation of GRFONT into packed
4C (binary) representation used by PGPLOT.
5C
6C This version ignores characters in the input file with Hershey
7C numbers 1000-1999 ("indexical" fonts) and 3000-3999 ("triplex"
8C and "gothic" fonts).
9C
10C The binary file contains one record, and is a direct copy of the
11C internal data structure used in PGPLOT. The format of the internal
12C data structure (and the binary file) are private to PGPLOT: i.e.,
13C they may be changed in a future release.
14C
15C NC1	Integer*4	Smallest Hershey number defined in file (1)
16C NC2	Integer*4	Largest Hershey number defined in file (3000)
17C NC3	Integer*4	Number of words of buffer space used
18C INDEX Integer*4 array (dimension 3000)
19C			Element NC of INDEX contains either 0 if
20C			NC is not a defined Hershey character, or the
21C			index in array BUFFER at which the digitization
22C                       of character number NC begins
23C BUFFER Integer*2 array (dimension 27000)
24C			Coordinate pairs defining each character are
25C			packed two to a word in this array.
26C
27C Note: the array sizes are fixed by dimension statements in PGPLOT.
28C New characters cannot be added if they would increase the size of
29C the arrays.  Array INDEX is not very efficiently used as only about
30C 1000 of the possible 3000 characters are defined.
31C-----------------------------------------------------------------------
32      INTEGER MAXCHR, MAXBUF
33      PARAMETER (MAXCHR=3000)
34      PARAMETER (MAXBUF=27000)
35C
36      INTEGER   INDEX(MAXCHR)
37      INTEGER*2 BUFFER(MAXBUF)
38      INTEGER   I, LENGTH, LOC, NC, NC1, NC2, NCHAR, XYGRID(400)
39C-----------------------------------------------------------------------
40 1000 FORMAT (7(2X,2I4))
41 2000 FORMAT (' Characters defined: ', I5/
42     1        ' Array cells used:   ', I5)
43 3000 FORMAT (' ++ERROR++ Buffer is too small: ',I7)
44C-----------------------------------------------------------------------
45C
46C Initialize index.
47C
48      DO 1 I=1,MAXCHR
49          INDEX(I) = 0
50    1 CONTINUE
51      LOC = 0
52      NCHAR = 0
53C
54C Open stdin.
55C
56C Read input file.
57C
58   10 CONTINUE
59C         -- read next character
60          READ (*,1000,END=20) NC,LENGTH,(XYGRID(I),I=1,5)
61          READ (*,1000) (XYGRID(I),I=6,LENGTH)
62C         -- skip if Hershey number is outside required range
63          IF (NC.LT.1 .OR. (NC.GT.999.AND.NC.LT.2000) .OR.
64     1        NC.GT.2999) GOTO 10
65C         -- store in index and buffer
66          NCHAR = NCHAR+1
67          LOC = LOC+1
68          IF (LOC.GT.MAXBUF) GOTO 500
69          INDEX(NC) = LOC
70          BUFFER(LOC) = XYGRID(1)
71          DO 15 I=2,LENGTH,2
72              LOC = LOC + 1
73              IF (LOC.GT.MAXBUF) GOTO 500
74              BUFFER(LOC) = 128*(XYGRID(I)+64) + XYGRID(I+1) + 64
75   15     CONTINUE
76      GOTO 10
77   20 CONTINUE
78C
79C Write output file.
80C
81      OPEN (UNIT=2, STATUS='NEW', FORM='UNFORMATTED', FILE='grfont.dat')
82      NC1 = 1
83      NC2 = 3000
84      WRITE (2) NC1,NC2,LOC,INDEX,BUFFER
85      CLOSE (UNIT=2)
86C
87C Write summary.
88C
89      WRITE (6,2000) NCHAR, LOC
90      STOP
91C
92C Error exit.
93C
94  500 WRITE (6,3000) MAXBUF
95C-----------------------------------------------------------------------
96      END
97