Article ID: 112339
Article Last Modified on 10/17/2003
c Compile options needed: none
c
include 'IO.FI'
program OPEN_TEST
character*9 fname/'FILE.000 '/
integer*4 j
fname(9:9) = CHAR(0) ! Append null character
do j = 1,100
write(*,*) fname
call open(fname)
write(fname(6:8),'(i3.3)') j ! Write file extension
enddo
end
c
subroutine open(name)
character*(*) name, buffer*16
integer lcreat, handle, len
data buffer/'Open many files.'/
handle = lcreat(name, 0) ! Create a new file
len = lwrite(handle, buffer, 16) ! Write to file
len = llseek(handle, 0, 0) ! Seek to the beginning
len = lread(handle, buffer, 16) ! Read data back from file
end
The following interface file, IO.FI, is used by the program above:
C Open an existing file
interface to integer function lopen
+ [stdcall, alias:'__lopen@8'](filename, mode)
character*1 filename[reference] ! null terminated file name
integer mode[value] ! 0 = read-only, 1 = write-only
! 2 = read-write
end
C Create a file (erase the old file if one exists)
interface to integer function lcreat
+ [stdcall, alias:'__lcreat@8'](filename, mode)
character*1 filename [reference] ! null terminated file name
integer mode[value] ! 0 = read-write, 1 = read-only
! 2 = hidden, 3 = system
end
C Close a file (use with files opened by lcreat or lopen)
interface to integer function lclose
+ [stdcall, alias:'__lclose@4'](handle)
integer handle[value]
end
C Move the file pointer to a specific offset in a file
interface to integer function llseek
+ [stdcall, alias:'__llseek@12'](handle,offset,origin)
integer handle[value]
integer offset[value] ! number of bytes to move pointer
integer origin[value] ! 0 = beginning, 1 = current position
! 2 = end of the file
end
C Read a specified number of bytes from a file
interface to integer function lread
+ [stdcall, alias:'__lread@12'](handle,buffer,length)
integer handle[value]
character*1 buffer
integer length[value] ! number of bytes
end
C Write a specified number of bytes to a file
interface to integer function lwrite
+ [stdcall, alias:'__lwrite@12'](handle,buffer,length)
integer handle[value]
character*1 buffer
integer length[value]
end
Additional query words: 1.00 4.00
Keywords: kblangfortran kbcode KB112339