Next: 3.4 Programming with dynamic arrays
Up: 3 Dynamic arrays
Prev: 3.2 Declaration of the super-array
Index
Contents
The utilities are described alphabetically in this section.
Essentially, the programmer initializes the super-array with
the aid of utility INITIS
(p. ), allocates dynamic arrays
with READRE, and frees them with
TUER. The uniqueness of each array name (parameter TAB)
is the programmer's responsibility.
The notation used for the utilities below |
is the usual notation (see Appendix A). |
SUBROUTINE IMATAB()
INTEGER M(*)
This utility prints the list of all the dynamic arrays allocated in M.
SUBROUTINE MAXTAM(,
,
)
INTEGER M(*), IATAB, LTAB
This utility determines the maximum size that can be allocated.
Warning: MAXTAM does not reserve the memory space found. The habitual use takes the following form:
... C --- DETERMINE THE MAXIMUM SIZE THAT CAN BE ALLOCATED CALL MAXTAM(M, IATAB, LMAX) C --- ALLOCATE AN ARRAY WITH THE MAXIMUM LENGTH NTYTAB = ... TAB = ... CALL READRE(NTYTAB, TAB, IATAB, LMAX, M, ICODE) C --- USE THIS ARRAY ... C --- DETERMINE THE SIZE ACTUALLY USED LTAB = ... C --- ADJUST THE SIZE OF THE ARRAY CALL READRE(NTYTAB, TAB, IATAB, LTAB, M, ICODE) ...
Remark: when several large arrays must be allocated, it is necessary to call MAXTAM several times:
... C ALLOCATE TWO LARGE ARRAYS WITH SIMILAR LENGTHS CALL MAXTAM(M, IAT1, LMAX) CALL READRE(1, 'T1', IAT1, LMAX/2, M, ICODE) CALL MAXTAM(M, IAT2, LMAX) CALL READRE(2, 'T2', IAT2, LMAX, M, ICODE) ...
SUBROUTINE READRE(,
,
,
,
,
)
INTEGER NTYTAB, IATAB, LTAB, M(*), ICODE
CHARACTER*(*) TAB
This utility allocates an array (the elements of this array are not initialized).
On exit, ICODE equals 1 if the array existed with the same length and type, 0 if not.
If LTAB = 0, no array is allocated, but on exit IATAB = 1. In fact, if IATAB was not initialized, passing M(IATAB) as a parameter may result in an execution error.
If the super-array does not contain an array with the same name, the allocation should not pose any difficulty. On the other hand, if an array with the same name exists already, it is "re-allocated" in the following manner:
Let
NTYTAB be the type requested,
NTYTAB be the type of the old array,
LTAB be the length requested, and
LTAB
be the length of the old array.
SUBROUTINE RENOMM(,
,
,
,
)
CHARACTER*(*) OLDTAB, NEWTAB
INTEGER IATAB, LTAB, M(*)
This utility renames an array, where
Warning: Errors are possible if OLDTAB and NEWTAB do not have the same number of characters.
SUBROUTINE TROUVE(,
,
,
,
,
)
INTEGER NTYTAB, IATAB, LTAB, ICODE, M(*)
CHARACTER*(*) TAB
This utility performs an array search by name. If the array is found, the exit parameters are updated. If not, IATAB = 0 on exit.
Parameter ICODE is only conserved for the sake of compatibility.
Remark: In principle, the programmer must conserve the address, IATAB, returned by READRE and avoid to call TROUVE (but it is not always possible!).
SUBROUTINE TUER(,
)
CHARACTER*(*) TAB
INTEGER M(*)
This utility frees an array (the space freed becomes available for a new allocation). For example, at the end of a module all work arrays must be deleted in this manner.
SUBROUTINE TYPCLA(,
,
)
INTEGER NTYTAB, NM1, NM2
This utility returns the type, NTYTAB, of an array using two integers, NM1 and NM2 (print using the Fortran format: 2A4):
ENTIER, REEL1MOT, LOGIQUE, CARACTER, REEL2MOT,
COMPLEXE, COMPLEX2.
SUBROUTINE TYPMOT(,
)
INTEGER NTYTAB, NBREMO
This utility returns the number of words occupied by an element of an array of type
NTYTAB. For example:
NTYTAB returns NBREMO = 1,
NTYTAB = 5 returns NBREMO = 2, ...