Re: DATA statement to initialise arrays
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: DATA statement to initialise arrays         

Group: comp.lang.fortran · Group Profile
Author: glen herrmannsfeldt
Date: Sep 19, 2008 12:55

Richard Maine wrote:
> dpb non.net> wrote:
>> DATA NEWVAL / MXL*MXD *0 /
>>if initialization expressions allowed "*", but they don't.
(snip)
> There are zillions of things that aren't allowed there in DATA
> statements. In fact, there are a lot more things that aren't allowed
> than that are. It is a special category of syntax all on its own rather
> than being a subset of a more general category such as initialization
> expressions. I'd think it simpler to keep track of what is allowed
> rather than with what isn't, except that...

As it hasn't been mentioned yet, be sure that you really do
want a DATA statement. Note that on most systems all the initializing
data goes into the object program. In the case of zeros it is sometimes
compressed out or otherwise doesn't take up so much space. You might
not notice at 100 but try this one:

integer x(1000000)
data x/1000000*1/
write(*,*) x(987654)
end

Compiling with g95 generates a 4001372 byte data.o file, and
4489684 byte a.out file. The above takes 14.5 seconds to
compile on my computer. At 2000000 it takes 29 seconds.
I would rather not try 100000000.
> I'd find it simplest to not keep track at all. For f90 and later (which
> is to say for anything today), I far prefer using initializers in type
> declaration statements.
(snip)
> On the type declaration statement, in an f90 style, you can just do
> integer :: newval (mxl,mxd) = 0

For static initialization I suppose I like it better, but
it makes it even less obvious that the result is the same
as the DATA statement. That is, that it usually stores all
the array element in the object file even though it looks like
just one integer value.

integer x(100000000)
x=1
write(*,*) x(987654)
end

takes less than a second to compile, generates a small
object program, and runs fairly fast. (2 cpu seconds,
23 real seconds, as I ran it on a machine with 256MB
of real memory.)

-- glen
no comments
diggit! del.icio.us! reddit!