HP 3000 Manuals

Transfer Procedures [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation


HP Pascal/iX Reference Manual

Transfer Procedures 

The transfer procedures supported by HP Pascal are pack and unpack.  A
description of these procedures follows.

pack 

Usage 

     pack(a, i, z) 

Parameters 

a          Any ARRAY [m..n] of t.

i          An expression that is type compatible with the index of the
           non-packed array.

z          Any PACKED ARRAY [u..v] of t.

Description 

The standard procedure pack transfers data from unpacked arrays to packed
arrays.  For example, assuming that a is an ARRAY[m..n] OF t and z is a
PACKED ARRAY[u..v] of t; the procedure pack(a, i, z) assigns components
of the unpacked array a, starting at component i, to each component of
the packed array z.

Because all the components of z are assigned a value, the normalized
value of i must be less than or equal to the difference between the
lengths of a and z + 1; for example, i-m+1 <= (n-m) - (v-u) + 1.
Otherwise, it is an error when pack attempts to access a nonexistent
component of a.

The component types of arrays a and z must be type identical.  The index
types of a and z, however, may be incompatible.

The call pack(a, i, z) is equivalent to:

     BEGIN
       k:= i;
       FOR j:= u TO v DO
         BEGIN
           z[j]:= a[k];
           IF j <> v THEN k:= succ(k);
         END;
     END;

where k and j are variables that are type compatible with the index type
of a and the index type of z, respectively.

Example 

     PROGRAM show_pack (input,output);
     TYPE
        clothes = (hat, glove, shirt, tie, sock);

     VAR
        dis : ARRAY [1..10] OF clothes;
        box : PACKED ARRAY [1..5] of clothes;
        index: integer;
        .
        .

     BEGIN
        .
        .
        index:= 1;
        pack(dis,index,box);   { After pack executes, box contains     }
        .                      { the first 5 components of dis.        }
        .
        index:= 8;
        pack(dis,index,box);   { An error results when pack attempts   }
        .                      { to access nonexistent 11th component  }
        .                      { of dis.                               }
     END.

unpack 

Usage 

     unpack(z, a, i) 

Parameters 

z          Any PACKED ARRAY [u..v] of t.

a          Any ARRAY [m..n] of t.

i          An expression that is type compatible with the index of the
           non-packed array.

Description 

This procedure transfers data from a packed array to an unpacked array.
For example, assuming that a is an ARRAY[m..n] OF t and z is a PACKED
ARRAY [u..v] OF t; the procedure unpack(z,a,i) successively assigns the
components of the packed array z, starting at component u, to the
components of the unpacked array a, starting at a [ i ].

All the components of z are assigned.  Also, the normalized value of i 
must be less than or equal to the difference between the lengths of a and
z + 1; for example, i-m+1 <= (n-m) - (v-u) + 1.  Otherwise, it is an
error when unpack attempts to index a beyond its upper bound.

The index types of a and z need not be compatible.  The components of the
two arrays, however, must be type identical.

The call unpack(z,a,i) is equivalent to:

     BEGIN
        k:= i;
        FOR j:= u TO v DO
           BEGIN
              a[k]:= z[j];
              IF j <> v THEN k:= succ(k);
           END;
       END;

where k and j are variables that are type compatible with the indices of
a and z respectively.

Example 

     PROGRAM show_unpack (input,output);

     TYPE
        suit_types = (casual, business, leisure, birthday);

     VAR
        suit : PACKED ARRAY [1..5] OF suit_types;
        kase : ARRAY [1..10] OF suit_types;
        i : integer;
        .
        .
     BEGIN
        .
        .
        i := 1;
        unpack(suit,kase,i);  { After execution, the first 5      }
        .                     { components of kase contain the    }
        .                     { value of suit.                    }
        .
        i := 7
        unpack(suit,kase,i);  { An error results because unpack   }
        .                     { attempts to assign a component of }
        .                     { suit to a component of kase which }
        .                     { is out of range.                  }
     END.



MPE/iX 5.0 Documentation