[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:53:28 EDT 2023
On 9/20/2023 7:39 PM, Arne Vajhøj wrote:
> 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:
...
> 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.
Alternatively I could have used non-existing records
to illustrate relative.
$ type rel3wrt.for
program rel3wrt
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, 2
write(buf,'(14HThis is line #,i4.4,2H!!)') i
write(unit=1,rec=i) buf
100 continue
close(unit=1)
end
$ for rel3wrt
$ link rel3wrt
$ run rel3wrt
$ type rel3rdseq.for
program rel3rdseq
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 rel3rdseq
$ link rel3rdseq
$ run rel3rdseq
|This is line #0001!!|
|This is line #0003!!|
...
|This is line #0099!!|
$ type rel3rddir.for
program rel3rddir
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, err=200) buf
write(*,*) '|'//buf//'|'
200 continue
close(unit=1)
end
$ for rel3rddir
$ link rel3rddir
$ run rel3rddir
|This is line #0001!!|
|This is line #0003!!|
...
|This is line #0099!!|
which can be done for org sequential but quite as nice:
$ type seq3wrt.for
program seq3wrt
integer*4 i
character*20 buf
open(unit=1,file='seq.dat',status='new',form='formatted',
+ organization='sequential',recl=20,recordtype='fixed',
+ access='direct')
do 100 i = 1, 100, 2
write(buf,'(14HThis is line #,i4.4,2H!!)') i
write(unit=1,rec=i) buf
100 continue
close(unit=1)
end
$ for seq3wrt
$ link seq3wrt
$ run seq3wrt
$ type seq3rdseq.for
program seq3rdseq
integer*4 i
character*20 buf
open(unit=1,file='seq.dat',status='old',form='formatted',
+ organization='sequential',recl=20,recordtype='fixed',
+ access='sequential')
100 read(unit=1,fmt='(a)',end=200) buf
if(buf(1:1).ne.char(0)) then
write(*,*) '|'//buf//'|'
end if
goto 100
200 close(unit=1)
end
$ for seq3rdseq
$ link seq3rdseq
$ run seq3rdseq
|This is line #0001!!|
|This is line #0003!!|
...
|This is line #0099!!|
$ type seq3rddir.for
program seq3rddir
integer*4 i
character*20 buf
open(unit=1,file='seq.dat',status='old',form='formatted',
+ organization='sequential',recl=20,recordtype='fixed',
+ access='direct')
do 200 i = 1, 100
read(unit=1,fmt='(a)',rec=i,err=200) buf
if(buf(1:1).ne.char(0)) then
write(*,*) '|'//buf//'|'
end if
200 continue
close(unit=1)
end
$ for seq3rddir
$ link seq3rddir
$ run seq3rddir
|This is line #0001!!|
|This is line #0003!!|
...
|This is line #0099!!|
Arne
More information about the Info-vax
mailing list