For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > Jagged arrays









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Jagged arrays
David Frank

2005-08-14, 9:00 am

Below was OT in "write checks" challenge.. Anyone have an opinion whether
the standard's syntax supports
"jagged arrays"


"Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
news:ddmafr$pok$1@scrotar.nss.udel.edu...
> David Frank wrote:
>
> Yep, use an array of ISO_VARYING_STRING datatypes.
>
> cheers,
>
> Rich



David Frank

2005-08-17, 4:07 am

Dick Hendrickson writes in "write checks" topic

======= begin copy ====
David Frank wrote:
> "Walt Brainerd" <walt@fortran.com> wrote in message
> news:42FE7B5B.2010203@fortran.com...
>
>
>
> I think Dick Hendrickson has posted that once a allocatable string is
> allocated it accepts assignments to
> a shorter or longer length, but will it accept assignment to a smaller or
> larger size?


Yes, the rule is in section 7.4.1.3 of THE STANDARD. It's a
two part rule to cover all of the cases.

1) If the left hand variable is allocated and the right and
variable differ in array shape (but can't differ in rank)
or any length parameter (like character length) then the
variable is deallocated.

2) If the variable is not allocated (perhaps because of rule
1), it is allocated with the right shape and lengths.

So, you can make them longer or shorter as you need.

>
> Assuming its true then having to allocate a allocatable string with a
> nominal len,size is DUMB!
>
> character(:),allocatable :: s(:)
> allocate ( character(1) :: s(1) ) ! nominal len,size
>
> s = ['quick','brown,'fox','jumps']


Your syntax here is incorrect, each element in an
array constructor must have the same length or you
must force the length with a declaration in the constructor.
Something like
s = [character(len=5)::'quick','brown,'fox',
'jumps']
will do the right thing.

The reason for requiring the length declaration is to
cover cases like
[ ( 'a', i = 1,n), ('bb', i = i,m) ...]
where it's not obvious what to do if any of the n, m, ...
are zero, or
[ (character_func(f(i)), i = g(), h() ) ]
where it's less than not obvious what to do if
g, h, or f do sufficiently interesting things.

Incidently, rule 2) says you don't need to preallocate s
before the assignment.
>
> AND, my question left hanging from your response is, can there be "jagged
> arrays"
> (string arrays whose elements have varying lens)

No, all arrays in Fortran are "rectangular" and all elements
of a character array have the same size. As someone (Rich I
think) said, you can have a (rectangular) array of
structures and each element can have different sized
internal parts.

Sorry if I'm repeating what others have said, I just got
back from vacation and am a little behind and out of order.

Dick Hendrickson

=== end copy ====




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com