Skip to content

PACK ARRAY

Pack String Array into String

This directive builds a string from the contents of a string array.

PACK ARRAY array-name [ALL] ,str-var [,pack-oper]
[,ERR=line-ref|,ERC=error-code]
array-name
is the name of an existing string array.
str-var
is the name of an existing string.
pack-oper
is a positive integer, which designates the packing operation to be performed:

0 normal packing; default

1 compressed packing; the values of all array elements are stored in the string of a compressed format.

line-ref
is the program line number or label to branch to if an error is produced.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

The format of a packed array string is as follows:

Bytes Description

1,1
Pack flag: the packing operation is stored in the high four bits and the number of dimensions is stored in the low four bits of the pack flag.
2,n
Dimension table: the format of a table entry is as follows:

1,4 base
3,4 dimension

The size of the dimension table (n) is computed by multiplying the number of dimensions by 8.

2+n,x Value contained in the first array element. The format of a packed value is as follows:

1,2
length of entry (m)
3,m
actual data
2+n+x+...,y
Value contained in the next array element, . . . and so on.

During compressed packing ( i.e., pack-oper = 1 ), the values of the array elements are stored in the packed array string after being compressed via the DCM( ) function.

If an array does not exist, an ERR=42 results.

If a pack-oper other than the integers 0 through 1 is specified, an ERR=41 results.

If there is not enough memory to build the packed array string, an ERR=33 results.

During a PACK ARRAY, if the size of the packed array string exceeds 32600 characters, an ERR=32 results.

DIM S$[-5:5];
FOR I=-5 TO 5;
S$[I]="ELEMENT "+STR(I);
NEXT I;
PACK ARRAY S$[ALL],P$

packs the contents of the array S$[ ] into P$.

DIM S$[3,4:6,5];
FOR X=0 TO 3;
X$=DIM(X+10,"X");
FOR Y=4 TO 6;
Y$=DIM(Y+10,"Y");
FOR Z=0 TO 5;
Z$=DIM(Z+10,"Z");
S$[X,Y,Z]=X$+","+Y$+","+Z$;
NEXT Z;
NEXT Y;
NEXT X;
PACK ARRAY S$[ALL],P$,1

packs the contents of the array S$[ ] into P$ with the data in compressed format.

UNPACK ARRAY directive

From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF