		NUCLEAR PHYSICS LABORATORY

		OXFORD.

		O.E.G. COMPUTER INFORMATION SHEET #10

		FEBRUARY 1970

	DYNAMICALLY DIMENSIONED ARRAYS
	------------------------------

		AN OFTEN SERIOUS LIMITATION OF THE FORTRAN IV LANGUAGE
	IS THAT ARRAYS MUST BE DIMENSIONED AT COMPILE TIME.  MANY PROGRAMS
	ARE RUN IN FAR MORE CORE THAN IS NECESSARY BECAUSE ARRAYS HAVE
	DIMENSIONS TO FIT THE LARGEST POSSIBLE ARRAYS WHICH MAY BE ENCOUNTERED.
	E.G.  AN ARRAY IS MADE LARGE ENOUGH TO HOLD AN 8K SPECTRA WHILE 
	USUALLY SPECTA OF ONLY 1 OR 2 K ARE PROCESSED.
	A SYSTEM OF DYNAMICALLY DIMENSIONED ARRAYS HAS BEEN DEVISED 
	WHICH SHOULD IN MOST CASES BE APPLICABLE BUT WHICH HAVE SOME RESTICTONS.

	THESE RESTRICTIONS ARE:
	1.	A DYNAMICALLY DIMENSIONED ARRAY MAY BE ACCESSED AS AN ARRAY ONLY IN 
	A SUBROUTINE OF THE PROGRAM IN WHICH IT IS DIMENSIONED.

	2.	A SUBROUTINE REFERENCING SUCH AN ARRAY MUST BE CALLED THROUGH
	A SPECIAL SUBROUTINE CALLED 'FAKE'.

	3.	ALTHOUGH THE ROUTINES INCLUDE PROVISIONS FOR RECLAIMING CORE, 
	THERE ARE RESTRICTION ON THE SETTING UP OF DEVICE BUFFERS WHEN
	THESE ROUTINES ARE USED.
	4.	THE ROUTINES WILL ATTEMPT TO EXPAND THE USER'S CORE WHEN 
	NECESSARY, HOWEVER WITHOUT A SWAPPING SYSTEM THIS IS NOT ALWAYS 
	POSSIBLE.
	5.	THE DIMENSIONS OF DYNAMIC ARRAYS MUST BE DEFINED IN THE 
	SUBROUTINES WHERE THEY ARE REFERENCED WITH ARGUMENTS IN THE CALLING
	STRING.

A)	SUBROUTINE DYNDIM
	-----------------

		THE MONITOR STORES THE ADDRESS OF THE FIRST FREE LOCATION
	OF THE USER'S CORE AREA IN 'JOBFF'.  THIS ROUTINE ASSIGNS CORE
	TO AN ARRAY STARTING AT THIS ADDRESS.  IT UPDATES 'JOBFF' TO 
	POINT TO THE FIRST LOCATION PAST THIS ARRAY.

	CALLING SEQUENCE:
		CALL DYNDIM(ARRAY,ID,IFLAG)
	WHERE	ARRAY IS A DUMMY ARRAY NAME
		ID IS THE NO OF WORDS REQUIRED FOR THE ARRAY

		IFLAG RETURNS TO THE USER
			=0 IF THE ARRAY IS O.K.
			=-1 IF NO CORE WAS AVAILABLE
			=+1 IF ID WAS < OR = 0.

	THE ROUTINE PLACES THE ADDRESS OF THE FIRST WORD ON THE ARRAY
	IN 'ARRAY', WHERE IT CAN BE FOUND BY 'FAKE'.

		THE SUBROUTINE WILL TYPE THE FOLLOWING ERROR MESSAGES FOR THE
	ERROR RETURNS.
	1.	'NO CORE AVAILABLE' IF, ON AN ATTEMP TO EXPAND CORE TO MAKE
	ROOM FOR THE ARRAY, NO CORE WAS AVAILABLE.

	2.	'CORE AVAILABLE, BUT NOT TO YOU' IF, ON AN ATTEMPT TO EXPAND
	CORE, THE REQUEST WAS NOT GRANTED BECAUSE EITHER IT WOULD
	EXCEED THE MAXIMUM CORE ALLOWED TO A USER (15K), OR ANOTHER
	PROGRAM WAS SITED IMMEDIATELY ABOVE THE USER PREVENTING CORE
	EXPANSION.

	3.	'ARRAY LENGTH < OR = 0 REQUESTED'.

	N.B. THERE IS NO RESTRICTION OF THE ORDER OF THE ARRAY, OR THE 
	NUMBER OF ARRAYS WHICH MAY BE DYNAMICALLY DIMENSIONED.

C)	SUBROUTINE FAKE
	---------------

		THIS ROUTINE IS AN INTERMEDIATE ROUTINE BETWEEN A PROGRAM WHERE
	A DYNAMIC ARRAY IS DIMENSIONED AND THE SUBROUTINE WHERE THE ARRAY 
	IS REFERENCED.  IT ISSUES A CALL TO THE USERS SUBROUTINE
	REPLACING THE ARRAY DUMMIES WITH THE ADDRESSES OF THE ARRAYS
	CONTAINED IN THE ARRAY DUMMIES.

	CALLING SEQUENCE:
		CALL FAKE(I,J,SUBPR,ARRAY1,ARRAY2......ARG1,ARG2,ARG3....)
	WHERE	I IS THE NUMBER OF DYNAMIC ARRAY DUMMIES, ARRAYN
		J IS THE TOTAL NUMBER OF ARGUMENTS FOR THE SUBROUTINE CALL TO
		GENERATED BY FAKE.

		SUBPR IS THE SUBROUTINE NAME, DEFINED IN THE FORTRAN PROGRAM
		IN AN EXTERNAL STATEMENT.

		ARRAYN ARE THE DYNAMICALLY DIMENSIONED ARRAY DUMMIES
		ARGN ARE THE REST OF THE ARGUMENTS NEEDED FOR THE SUBROUTINE CALL


		FAKE WILL GENERATE THE FOLLOWING CALL STRING
		CALL SUBPR(ARADR1,ARADR2.....ARG1,ARG2,ARG3...)
	WHERE 'ARADRN' ARE THE ARRAY ADDRESSES WHICH WERE PLACED IN THE
	ARRAY DUMMIES 'ARRAYN' BY 'DYNDIM'.
		THE MAXIMUM NUMBER OF ARGUMENTS IN THE FINAL CALL STRING (I.E. THE
	MAXIMUM VALUE OF J) IS 20.



D)	SUBROUTINE SETJFF
	-----------------

		THIS ROUTINE ALLOWS A USER TO SAVE AND RESTORE THE ADDRESS OF 
	THE FIRST FREE LOCATION IN THE USERS AREA (JOBFF).

	CALLING SEQUENCE:
		CALL SETJFF(NCOR)
	WHERE	NCOR=0 CAUSES JOBFF TO BE SAVED, AND NCOR TO BE RETURNED
	NON-ZERO.

		NCOR NON-ZERO CAUSES JOBFF TO BE RESTORED TO ITS SAVED VALUE.

		DEVICE BUFFERS ARE ALSO SET UP AT RUN TIME WITH REFERENCE TO JOBFF.
	FOR THIS REASON ANY DEVICE WHICH HAS SET UP BUFFERS AFTER JOBFF
	HAS BEEN SAVED, MUST BE RELEASED BEFORE JOBFF IS RESTORED.
	IN FORTRAN IV BUFFERS ARE SET UP FOR A DEVICE WHEN IT IS FIRST
	REFERENCED OR BY CALLING THE LIBRARY ROUTINE 'BUFFER'.

	EXAMPLE
	-------


			.
			.
			.
		DIMENSION NDATA(10)
	C   DUMMY ARRAY NAMES FOR TEN SLICES
		EXTERNAL SRTWR
	C   SUBROUTINE NAME
		NCOR=0
		ILPT=3
	10	CALL BUFFER(ILPT,2,2)
	C   SET UP TWO RING BUFFER FOR OUPUT ON ILPT TO PREVENT COMPLICATIONS
	C   IN RECOVERING ARRAY SPACE
	20	CALL SETJFF(NCOR)
	C   SAVE AND RESTORE JOBFF.
	C   SAVE JOBFF FIRST TIME THROUGH (NCOR=0), AFTER THAT RESTORE JOBFF(NCOR=1)
			.
			.
			.
		DO 2000 I=1,NUMSL
			.
			.
			.
		CALL DYNDIM(NDATA(I),IDIM(I),IFLAG)
	C   SET UP A DIFFERENT ARRAY FOR EACH SLICE
		IF(IFLAG.LT.0) GO TO......
	C   CORE NOT AVAILABLE?
		IF(IFLAG.EQ.1)GO TO.......
	C   DIMENSION < OR = 0?
			.

			.
			.
	2000	CONTINUE
			.
			.
			.
		DO 2020 I=1,NUMSL
		CALL FAKE(1,4,SRTWR,NDATA(I),IDIM(I),NAME(I),I)
	C   OUTPUT CONTENTS OF SLICE ARRAYS
	2020	CONTINUE
			.
			.
			.
		GO TO 20
			.
			.

**********************************************************************
