18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced Topics<br />

(a) for I = 1 to 10, read CUBE(J+7,K+L,I)<br />

(b) let DUMMY(*) = CUBE(J+7,K+L,*)<br />

for I=1 to 10, read DUMMY(I)<br />

where DUMMY has been defined as a one-dimensional array, of the same mode as CUBE, but has not<br />

been reserved. The revised statement eliminates the need for recomputing the subscripts of CUBE<br />

not affected by the for loop every time a new element is accessed. Little additional memory space<br />

is taken, for the array DUMMY never has more space allocated than is needed for its base pointer.<br />

DATA ELEMENTS<br />

⎧ TABLE(1,1)<br />

⎨ TABLE(1,2)<br />

⎪ TABLE(1,3)<br />

⎩ TABLE(1,4)<br />

⎧ TABLE(2,1)<br />

⎨ TABLE(2,2)<br />

ROW POINTERS<br />

⎩<br />

⎧ TABLE(1,*) ⎧ TABLE(3,1)<br />

BASE POINTER ⎪ TABLE(2,*) ⎪ TABLE(3,2)<br />

TABLE(*,*) ⎨ TABLE(3,*) ⎨ TABLE(3,3)<br />

⎪ TABLE(4,*) ⎪ TABLE(3,4)<br />

⎩ TABLE(5,*) ⎪ TABLE(3,5)<br />

⎩ TABLE(3,6)<br />

{ TABLE(4,1)<br />

⎧ TABLE(5,1)<br />

⎨ TABLE(5,2)<br />

⎩ TABLE(5,3)<br />

Figure 6-5. Memory Structure After Assignment of Data Arrays to Row Pointers<br />

3. It has already been stated that once an array has been reserved, it cannot be reserved<br />

again. The <strong>SIMSCRIPT</strong> <strong>II.5</strong> system ignores instructions to reserve an array when the<br />

pointer to the array already has a value. When a program is first initialized, all array<br />

pointers are zero, making the first reserve possible. After this, the presence of a nonzero<br />

value in a pointer variable dictates whether or not a reserve will be executed. This<br />

makes it possible to use a reserve statement more than once to reserve multiple instances<br />

of an array by saving the value of the array base pointer and then resetting it to zero<br />

before the second and subsequent reserves. Any specific instance of the array may be<br />

accessed by restoring the value of the appropriate base pointer. The example below illustrates<br />

how such a mechanism can be employed:<br />

A program is to be developed to store genealogical information in the form of a<br />

family tree. Such a tree has an individual at its apex, his parents at the next level,<br />

his parents' parents below that, and so on. Figure 6-6 illustrates a family tree containing<br />

four levels of genealogical information.<br />

This information can be stored in a rectangular array, as depicted in figure 6-7.<br />

While simple enough to do, there is a waste of computer memory because of all the<br />

empty cells.<br />

253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!