function IGlobal ( Command, Name, Value ) c c------------------------------------------------------------------------------ c c >>> IGlobal -- INTEGER global variable saver routine c c *** Calling Sequence: Result = IGlobal(Command,Name,Value) c c --- on entry the calling routine supplies -- c c Command -- CHARACTER string indicating whether the indicated global c variable is to be saved, retrieved, or deleted c Possible Commands are: c Command = 'save' to save a global c Command = 'get' to retrieve one c Command = 'delete' to remove one c Command = 'list' to write EVERYTHING c NOTE: only the first CHARACTER of Command is significant c c Name -- CHARACTER string (8 or fewer CHARACTERs) indicating the c unique name of the global to be saved/retrieved/etc. c c Value -- INTEGER which is an input variable if Command='save' c If Command .ne. 'save', Value is not read on input. c c --- on exit the routine returns -- c c Value -- is an output INTEGER variable only if Command='get', in c which case the remembered value of the Name-d c global variable is returned. c c IGlobal -- is a CHARACTER string indicating the success/failure of c the operation. Possible returns are: c IGlobal = 'OK' if all was OK c IGlobal = 'CANT' if no internal space left on c a 'save' operation, or if the c Named variable is not here on c a 'delete' or 'get'. c IGlobal = 'WHAT' if Command unrecognized c c------------------------------------------------------------------------------ c c CHARACTER*(8) IGlobal CHARACTER*(*) Command CHARACTER*(*) Name INTEGER Value c INTEGER MAXSave PARAMETER (MAXSave=100) c INTEGER NSaved c * * * * * ! loop index INTEGER i c * * * * * ! new value of NSaved INTEGER new c * * * * * ! value of output unit if 'list' INTEGER iout c INTEGER Save(MAXSave) CHARACTER*8 VNames(MAXSave) c SAVE c data NSaved / 5 / c data VNames(1) / 'StdIn' / data Save(1) / 9 / c data VNames(2) / 'StdOut' / data Save(2) / 9 / c data VNames(3) / 'StdErr' / data Save(3) / 9 / c data VNames(4) / 'StdDbg' / data Save(4) / 9 / c data VNames(5) / 'StdWrt' / data Save(5) / 9 / c c c---------------------------- execution begins here --------------------------- c c c --- blank Names NOT allowed --- c IF( Name .eq. ' ' )THEN IGlobal = 'CANT' RETURN ENDIF c c --- special case if Command = 'list' --- c IF( Command(1:1) .eq. 'l' )THEN DO 100 i = 1, NSaved IF( Name .eq. VNames(i) )THEN iout = Save(i) go to 101 ENDIF 100 continue iout = 0 IGlobal = 'CANT' 101 continue IF( iout .eq. 0 ) RETURN c WRITE( iout, * ) ' === Integer Globals ===' DO 200 i = 1, NSaved IF( VNames(i) .ne. ' ' )THEN WRITE( iout, '(5x,a8,'' = '',i10)' ) VNames(i), Save(i) ENDIF 200 continue IGlobal = 'OK' RETURN ENDIF c c --- has Name already been defined? --- c DO 1 i = 1, NSaved IF( Name .eq. VNames(i) ) go to 2 1 continue i = 0 2 continue c c---------------------------- saving a value ---------------------------------- c IF ( Command(1:1) .eq. 's' )THEN c IF( i .eq. 0 )THEN new = NSaved + 1 IF( new .gt. MAXSave )THEN c c --- arrays full, look for a blank entry --- c DO 10 i = 1, NSaved IF( VNames(i) .eq. ' ' ) go to 11 10 continue i = 0 11 continue IF( i .eq. 0 )THEN IGlobal = 'CANT' RETURN ELSE new = NSaved ENDIF ENDIF c c --- save value for the newly defined global --- c NSaved = new VNames(NSaved) = Name Save(NSaved) = Value IGlobal = 'OK' c c --- save a new value for a previously defined global --- c ELSE Save(i) = Value IGlobal = 'OK' ENDIF c c----------------------------- retrieving a value ----------------------------- c ELSEIF ( Command(1:1) .eq. 'g' )THEN c IF( i .eq. 0 )THEN IGlobal = 'CANT' ELSE IGlobal = 'OK' Value = Save(i) ENDIF c c----------------------------- deleting a global ------------------------------- c ELSEIF ( Command(1:1) .eq. 'd' )THEN c IF( i .eq. 0 )THEN IGlobal = 'CANT' ELSE IGlobal = 'OK' VNames(i) = ' ' ENDIF c c---------------------------- unrecognized command ---------------------------- c ELSE IGlobal = 'WHAT' ENDIF c RETURN end