[Info-vax] Example of random access by record number on an RMS fixed record size, relative organization file?
Arne Vajhøj
arne at vajhoej.dk
Wed Sep 20 19:39:33 EDT 2023
On 9/20/2023 8:22 AM, Simon Clubley wrote:
> On 2023-09-20, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> On 9/19/2023 11:15 PM, gah4 wrote:
>>> On Tuesday, September 19, 2023 at 5:46:29?PM UTC-7, Arne Vajhøj wrote:
>>>> open(unit=1,file='rel.dat',status='new',form='formatted',
>>>> + organization='relative',recl=512,recordtype='variable',
>>>> + access='direct')
>>>
>>> OP asked about fixed record size, and traditionally that is
>>> the way it was done. I haven't followed that detail of later
>>> Fortran standards. They have to, at least, allocate to the
>>> maximum size.
>>
>> True.
>>
>> I added a little more for my example.
>>
>> If I understand the docs correctly then the above
>> allocates 512 bytes (per recl) for each cell, but
>> handles actual lengths 0-512 within that cell.
>
> It allocates 512 bytes for the _data_ within that cell. It then allocates
> a bit more per record to store the length of each record. Look at the
> example Hein posted.
>
> $ set response/mode=good_natured
>
> Even without your statement about never having used relative files,
> at this point I would be actively suspecting that to be the case. :-)
>
> I _have_ used relative files in the past in a number of cases, but I have
> never, ever, used anything other than fixed length records with them.
>
> The idea of variable length records within a relative file is utterly
> alien to me.
Maybe.
I could have used fixed:
$ type rel2wrt.for
program rel2wrt
integer*4 i
character*20 buf
open(unit=1,file='rel.dat',status='new',form='formatted',
+ organization='relative',recl=20,recordtype='fixed',
+ access='direct')
do 100 i = 1, 100
write(buf,'(14HThis is line #,i4.4,2H!!)') i
write(unit=1,rec=i) buf
100 continue
close(unit=1)
end
$ for rel2wrt
$ link rel2wrt
$ run rel2wrt
$ type rel2rdseq.for
program rel2rdseq
integer*4 i
character*20 buf
open(unit=1,file='rel.dat',status='old',form='formatted',
+ organization='relative',recl=20,recordtype='fixed',
+ access='sequential')
100 read(unit=1,fmt='(a)',end=200) buf
write(*,*) '|'//buf//'|'
goto 100
200 close(unit=1)
end
$ for rel2rdseq
$ link rel2rdseq
$ run rel2rdseq
|This is line #0001!!|
|This is line #0002!!|
...
|This is line #0100!!|
$ type rel2rddir.for
program rel2rddir
integer*4 i
character*20 buf
open(unit=1,file='rel.dat',status='old',form='formatted',
+ organization='relative',recl=20,recordtype='fixed',
+ access='direct')
do 200 i = 1, 100
read(unit=1,fmt='(a)',rec=i) buf
write(*,*) '|'//buf//'|'
200 continue
close(unit=1)
end
$ for rel2rddir
$ link rel2rddir
$ run rel2rddir
|This is line #0001!!|
|This is line #0002!!|
...
|This is line #0100!!|
But the point was to illustrate usage of relative files.
The code above is a very poor illustration of relative files.
Because there is nothing relative specific in it. The exact same code
works fine with:
organization='sequential'
Direct access for rfm fixed works fine even for org sequential. No need
for org relative.
Direct access for rfm variable does not work for org sequential only
for org relative.
Arne
More information about the Info-vax
mailing list