internal READ from a CHARACTER array? 
Author Message
 internal READ from a CHARACTER array?

Is it legal in fortran 90 or 95 to do an internal READ from an array
of CHARACTER variables? The code I have seen in textbooks always shows
internal READ being done on a scalar CHARACTER variable, but Compaq,
Lahey/Fujitsu, Absoft, NA Software, and Portland Group all allow an
internal READ of a CHARACTER array. According to the CVF help file, an
internal unit "must be a character variable. It must not be an array
section with a vector subscript." For the code

program xread_vec
implicit none
integer, parameter :: n = 2
character (len=1)  :: cc(n) = (/"5","9"/)
integer            :: ii(n)
read (cc,*) ii
print*,"ii =",ii
end program xread_vec

All compilers give the output (modulo spacing)

ii = 5 9



Thu, 20 Jul 2006 22:52:45 GMT  
 internal READ from a CHARACTER array?

Quote:

> Is it legal in Fortran 90 or 95 to do an internal READ from an array
> of CHARACTER variables?

Yes.  Perfectly standard conforming, even in f77.  (Except that there
is no such thing as an array of variables, but I'll interpret that
as an array variable, which is certainly what you meant).

Each element of the array is a record of the internal file.  Do note
that this is different from just concatenating all the elements
together (as with arrays used for a format).  With the list-directed
sample you used, that distinction is obscured because list-directed
reads will freely go to new records.

The multi-record thing is part of why you don't see arrays so much.
There isn't a concept of file position that survives past a single
read statement for an internal file.   Most read statements read
only a single record, which corresponds to most internal reads
being scalar.  Exceptions aren't particularly rare, but the single
record case is the most common by at least some (vague) margin.

Quote:
> It must not be an array
> section with a vector subscript."

I'd believe that restriction.  I'd have to go look it up to be sure,
but it sounds quite likely.  Array sections with vector subscripts
are restricted in lots of contexts.

--
Richard Maine
email: my last name at domain
domain: sumertriangle dot net



Fri, 21 Jul 2006 01:16:48 GMT  
 internal READ from a CHARACTER array?


Quote:

>> Is it legal in Fortran 90 or 95 to do an internal READ from an array
>> of CHARACTER variables?

>Yes.  Perfectly standard conforming, even in f77.  (Except that there
>is no such thing as an array of variables, but I'll interpret that
>as an array variable, which is certainly what you meant).

>Each element of the array is a record of the internal file.  Do note
>that this is different from just concatenating all the elements
>together (as with arrays used for a format).  With the list-directed
>sample you used, that distinction is obscured because list-directed
>reads will freely go to new records.

>The multi-record thing is part of why you don't see arrays so much.
>There isn't a concept of file position that survives past a single
>read statement for an internal file.   Most read statements read
>only a single record, which corresponds to most internal reads
>being scalar.  Exceptions aren't particularly rare, but the single
>record case is the most common by at least some (vague) margin.

>> It must not be an array
>> section with a vector subscript."

>I'd believe that restriction.  I'd have to go look it up to be sure,
>but it sounds quite likely.  Array sections with vector subscripts
>are restricted in lots of contexts.

Just to add, your actual example wasn't standard conforming f77 because
you couldn't do list-directed reads in internal i/o. A really simple
little thing, but probably one of the F95 features I use most.

Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".



Fri, 21 Jul 2006 17:29:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. internal read of character array. F/ifort differences

2. (subtypep '(simple-array character (*)) '(array character (*)))

3. Reading script from a character array

4. Reading from a character array

5. difference between character and character array

6. Array of character vs. character*ii

7. Declaring array of character arrays

8. Internal Files: convert numeric value to character form

9. Problem with Read while reading part of character arrays.

10. Reading/Assigning to internal signals

11. access error on internal read

12. internal procedure can't use array of derived type from main

 

 
Powered by phpBB® Forum Software