subroutine openn(UNIT,ENVcod)
c
c Associate a file specified by ENVcod with a Fortran UNIT number.
c ENVcod is assumed to lie between 0 and 9 inclusive.
c ENVcod = 0 specifies the character card(s), assumed to reside in
c the file whose name is the value of the environment variable CHARCARD.
c ENVcod = i specifies the file whose name is the value of the environment
c variable FILEi.
c
integer UNIT, ENVcod
character null
character*50 getenv, value
parameter (null = '\0')
integer ichar
character char
if (ENVcod .eq. 0) then
value = getenv( 'CHARCARD' )
else if (ENVcod .eq. 1) then
value = getenv ( 'FILE1' )
else if (ENVcod .eq. 2) then
value = getenv ( 'FILE2' )
else if (ENVcod .eq. 3) then
value = getenv ( 'FILE3' )
else if (ENVcod .eq. 4) then
value = getenv ( 'FILE4' )
else if (ENVcod .eq. 5) then
value = getenv ( 'FILE5' )
else if (ENVcod .eq. 6) then
value = getenv ( 'FILE6' )
else if (ENVcod .eq. 7) then
value = getenv ( 'FILE7' )
else if (ENVcod .eq. 8) then
value = getenv ( 'FILE8' )
else if (ENVcod .eq. 9) then
value = getenv ( 'FILE9' )
else
print*, "(openn) ENVcod =", ENVcod, "out of range"
stop
endif
if (value(1:1) .eq. null) then
print*, '(openn) environment variable',
$ 'FILE'//char(ichar('0')+ENVcod), ' is undefined'
stop
endif
open( UNIT , file = value )
rewind UNIT
return
end