C+
C NAME:
C	OpenTest
C PURPOSE:
C	Test program for bOpenFile
C CATEGORY:
C	Test: bOpenFile
C CALLING SEQUENCE:
C	run $EXE:OPENTEST
C INPUTS:
C	(none)
C OUTPUTS:
C	(none)
C CALLS:
C	iFilePath, bOpenFile, iFreeLun, itrim
C PROCEDURE:
C	Creates, writes to and reads from a temporary file using
C	bOpenFile with various qualifiers.
C MODIFICATION HISTORY:
C	MAY-2000, Paul Hick (UCSD; pphick@ucsd.edu)
C-
	program OpenTest
	character       cFile*80
	logical         bOpenFile
	include         'dirspec.h'
	include         'openfile.h'
	include         'filparts.h'

	nRecl = 10

	x1 = 12.3
	x2 = 32.1
	iAct0 = OPN__TRYINPUT+OPN__ONEPASS

C-------        NEW FILES

	i = iFilePath(cTemp,0,' ','test1.txt',cFile)
	iAct = iAct0+OPN__NEW+OPN__SEQUENTIAL+OPN__FORMATTED

	print *, 'new, sequential, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    write (iU,'(2F7.2)') x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test2.txt',cFile)
	iAct = iAct0+OPN__NEW+OPN__SEQUENTIAL

	print *, 'new, sequential, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    write (iU) x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test3.txt',cFile)
	iAct = iAct0+OPN__NEW+OPN__FORMATTED

	print *, 'new, direct, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    if (cOpSys .eq. OS__UNIX) write (iU,'(2F7.2)') x1,x2
	    if (cOpSys .eq. OS__VMS ) write (iU,rec=1) x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test4.txt',cFile)
	iAct = iAct0+OPN__NEW

	print *, 'new, direct, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    write (iU,rec=1) x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

C-------        OLD FILES
C APPEND
	i = iFilePath(cTemp,0,' ','test1.txt',cFile)
	iAct = iAct0+OPN__APPEND+OPN__FORMATTED

	print *, 'old, append, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    write (iU,'(2F7.2)') 2*x1,2*x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test2.txt',cFile)
	iAct = iAct0+OPN__APPEND

	print *, 'old, append, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    write (iU) 2*x1,2*x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

C OLD
	i = iFilePath(cTemp,0,' ','test1.txt',cFile)
	iAct = iAct0+OPN__SEQUENTIAL+OPN__FORMATTED

	print *, 'old, sequential, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    x1 = -1
	    x2 = -1
	    read (iU,'(2F7.2)') x1,x2
	    print *, x1,x2
	    x1 = -1
	    x2 = -1
	    read (iU,'(2F7.2)') x1,x2
	    print *, x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test2.txt',cFile)
	iAct = iAct0+OPN__SEQUENTIAL

	print *, 'old, sequential, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    x1 = -1
	    x2 = -1
	    read (iU) x1,x2
	    print *, x1, x2
	    x1 = -1
	    x2 = -1
	    read (iU) x1,x2
	    print *, x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test3.txt',cFile)
	iAct = iAct0+OPN__FORMATTED

	print *, 'old, direct, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    x1 = -1
	    x2 = -1
	    if (cOpSys .eq. OS__VMS ) read (iU,rec=1) x1,x2
	    if (cOpSys .eq. OS__UNIX) read (iU,'(2F7.2)') x1,x2
	    print *, x1, x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test4.txt',cFile)
	iAct = iAct0

	print *, 'old, direct, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    x1 = -1
	    x2 = -1
	    read (iU,rec=1) x1,x2
	    print *, x1,x2
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

C-------        READONLY FILES

	i = iFilePath(cTemp,0,' ','test1.txt',cFile)
	iAct = iAct0+OPN__SEQUENTIAL+OPN__FORMATTED+OPN__READONLY

	print *, 'readonly, sequential, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test2.txt',cFile)
	iAct = iAct0+OPN__SEQUENTIAL+OPN__READONLY

	print *, 'readonly, sequential, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test3.txt',cFile)
	iAct = iAct0+OPN__FORMATTED+OPN__READONLY

	print *, 'readonly, direct, formatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	i = iFilePath(cTemp,0,' ','test4.txt',cFile)
	iAct = iAct0+OPN__READONLY

	print *, 'readonly, direct, unformatted: ',cFile(:itrim(cFile))
	iRecl = nRecl
	if (bOpenFile(iAct,iU,cFile,iRecl)) then
	    iU = iFreeLun(iU)
	    print *, 'recl=',nRecl,iRecl
	else
	    print *, 'open failed'
	end if

	stop 'done'
	end
