If I understand correctly Alek's would like to do something like (note
the TRIM):
WRITE(IUNIT) TRIM(STR)
and later ...
READ(IUNIT) STR
This will, in general, fail because the number of bytes written will be
less than the number of bytes that one is attempting to read.
One way to make writing "variable-length" strings work is, (as Alek's
has done, if I understand correctly) as follows. Sure, its another four,
possibly eight, bytes per "variable-length" string but it is portable.
WRITE(IUNIT) LEN_TRIM(STR)
WRITE(IUNIT) TRIM(STR)
and later ...
READ(IUNIT) LEN
READ(IUNIT) STR(1:LEN)
To skip a variable length string simply requires two "empty" reads, to
skip the string length and the string itself:
READ(IUNIT)
READ(IUNIT)
Cheers,
David.
Dan Nagle wrote:
> Hello,
>
> Aleksandar Donev wrote:
>> On Friday 22 June 2007 15:26, Bill Long wrote:
>>
>>> The number of bytes required by the input variable list is allowed
>>> to be
>>> smaller than the size of the record.
>> OK, that's nice. From what Dan said I can also just read a blank
>> record (no items). MRC book says that "on input, the type and type
>> parameters of each entity in the list must agree with those of the
>> value in the record..." Character strings may be, as usual, an
>> exception (like COMPLEX is)?
>
> Hint: What about entities that *aren't* on the list?
> Must they agree with anything?
>
>> Dan added:
>>
>>> If sequential, read a record. If direct, increment the record number.
>> It is sequential...what I wan't sure is what kind of record to read
>> (see above about matching types etc.)---I don't know the length of
>> the string written to that record.
>
> Why do you want to know the length?
>
>>> BTW, the "usual" implementation for unformatted sequential access
>>> is to store the record length before and after the record itself.
>> But it is not possible for a user to find out the length? I guess I
>> could try reading more and more characters into an array until the
>> I/O statement fails? If it is in the file, it seems a pity to me not
>> to be able to read it directly :-\
>
> Hint: What does read( unit) do?
>
> Good grief, Alek, this is a one-line test!
>
--
David Vowles,
Research Engineer,
School of Electrical and Electronic Engineering,
The University of Adelaide,
Australia, 5005.
Phone: +61 8 8303 5416
Fax: +61 8 8303 4360
|