PSS ID Number: 102698
Article Last Modified on 5/5/2001
C Open an existing file
interface to integer*2 function lopen
+ [pascal, alias:'_lopen'](filename, mode)
character*1 filename[reference]
integer*2 mode[value]
C MODE =
C 0 Read-only
C 1 Write-only
C 2 Read and write
end
C Create a file (erase the old file if one exists)
interface to integer*2 function lcreat
+ [pascal, alias:'_lcreat'](filename, mode)
character*1 filename[reference]
integer*2 mode[value]
C MODE =
C 0 Read and write
C 1 Read-only
C 2 Hidden
C 3 System
end
C Close a file (use with files opened by lcreat or lopen)
interface to integer*2 function lclose
+ [pascal, alias:'_lclose'](handle)
integer*2 handle[value]
end
C hread and hwrite can read or write a buffer larger than 64K
interface to integer*4 function hwrite
+ [pascal, alias:'_hwrite'](handle, buf, size)
character*1 buf[reference]
integer*2 handle[value]
integer*4 size[value]
end
interface to integer*4 function hread
+ [pascal, alias:'_hread'](handle, buf, size)
character*1 buf[reference]
integer*2 handle[value]
integer*4 size[value]
end
C Seek to a point in a file (used to provide direct file access)
interface to integer*4 function llseek
+ [pascal, alias:'_llseek'](handle, offset, origin)
integer*4 offset[value]
integer*2 handle[value], origin[value]
C Origin =
C 0 Offset from start of file
C 1 Offset from current position
C 2 Offset from end of file
end
C Read and write binary floating-point data
interface to integer*4 function bfwrite
+ [pascal, alias:'_hwrite'](handle, buf, size)
real*4 buf[reference](1)
integer*2 handle[value]
integer*4 size[value]
end
interface to integer*4 function bfread
+ [pascal, alias:'_hread'](handle, buf, size)
real*4 buf[reference](1)
integer*2 handle[value]
integer*4 size[value]
end
C Write ASCII and binary data
subroutine testwrite()
character*30 str
integer*2 handle, lclose, lcreat
integer*4 i, hwrite, bfwrite
real*4 x(20000) ! Note: X is 80000 bytes
handle = lcreat('testbf.out'C, 0) ! Create new file
do i= 2, 20000
x(i) = x(i - 1) + 3.1415926
end do
i = bfwrite(handle, x, 80000) ! Binary write all of X
i = lclose(handle)
handle = lcreat('test.out'C, 0) ! Create new file
! Use an internal write to format output text
write(str, '(''Test One'', F12.5)') 51.763
i = hwrite(handle, str, 20) ! then write output text
i = lclose(handle)
end
C Read binary data
subroutine readbinary()
character*24 str
integer*2 j, handle, lclose, lopen, lcreat
integer*4 i, hwrite, bfread
real*4 x(20000) ! Note: X is 80000 bytes
handle = lopen('testbf.out'C, 2) ! Open existing file
i = bfread(handle, x, 80000) ! Binary read all of X
i = lclose(handle)
handle = lcreat('testbf_o.out'C, 0) ! Create new file
do j = 1, 4
write(str, '(F16.5)') x(j) ! Convert to text
i = hwrite(handle, str, 16) ! Write formatted output
end do
write(str, '(F16.5)') x(20000)
i = hwrite(handle, str, 16)
i = lclose(handle)
end
C Randomly access a file
subroutine testseek()
character*40 str
integer*2 handle, lclose, lopen
integer*4 i, hwrite, llseek, hread
handle = lopen('test.out'C, 2)
i = llseek(handle, 4, 0) ! Position to 4 bytes from start
i = hread(handle, str, 16) ! Read 16 characters
i = llseek(handle, 7, 0) ! Position to 7 bytes from start
i = hwrite(handle, str, 16) ! Overwrite from position 7 on
i = lclose(handle)
end
FORTIO.DEF
----------
LIBRARY FORTIO
EXETYPE WINDOWS 3.1
PROTMODE
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE SINGLE
HEAPSIZE 1024
EXPORTS WEP @1 RESIDENTNAME
TESTWRITE
TESTSEEK
READBINARY
TEST.FOR
--------
call testwrite
print *,"testwrite - Created 'test.out' and 'testbf.out'"
print *, 'Check them out (Hit return to continue)'
read *
call readbinary
print *, "readbinary - Created 'testbf_o.out'"
print *, 'Check it out (Hit return to continue)'
read *
call testseek ! modify 'test.out'
print *, "testseek - Modified 'test.out'"
end
HUGE.DEF
--------
LIBRARY KERNEL
EXPORTS _hread
_hwrite
FORTIO.MAK
----------
all: test.exe
test.exe: fortio.lib test.obj
link /NOD test.obj, , nul, llibfew + fortio.lib,\
c:\fortran\binb\fl.def;
test.obj: test.for
fl /c /MW test.for
fortio.lib: fortio.dll
implib fortio.lib fortio.dll
fortio.dll: fortio.obj fortio.def huge.lib
link /NOD fortio.obj, fortio.dll, nul,\
ldllfew.lib + huge.lib, fortio.def;
fortio.obj: fortio.for
fl /c /Aw /Gw fortio.for
huge.lib: huge.def
implib huge.lib huge.def
Additional query words: kbinf 5.10
Keywords: KB102698
Technology: kbAudDeveloper kbFORTRAN510DOS kbFortranSearch kbZNotKeyword3