Re: 77 to 90/95 assignment question.



Richard Maine wrote:
B <execrable@xxxxxxxxx> wrote:

Is there a way to change a data statement like the one below to an assignment statement in f90/95 that is just as compact?

data (mattabnm(j),(mattabs(i,j),i=1,3),j= 1,10) /
1 'h ', 5251, 15250, 25251,
2 'd ', 5263, 15263, 25251,
3 't ', 5263, 15263, 25251,
4 'dt ', 5271, 15263, 25270,
5 'he ', 5760, 15760, 25760,
6 'li-7 ', 2292, 12290, 22294,
7 'be ', 2020, 12020, 22020,
8 'he-4 ', 5762, 15760, 25760,
9 'c ', 7831, 17830, 27834,
a 'ch ', 7590, 17590, 27590 /

Well, I'm not quite sure what you mean by "compact" in this case. The
most obvious translation to an assignment statement (and note that the
above data statement is perfectly legitimate f90/f95) is something like

mattabnm = ['h ',.....]
mattabs = reshape([5251,...],[3,10])

where I have taken the liberty of using the f2003 [...]. To stick with
stricy f90/f95, substitute (/.../). I've also assumed that the arrays
have the implied dimensions so that slices aren't needed.

I didn't count characters, but it is at least roughtly the same number,
if that's what you mean by "compact". The reshape adds a few, but
getting rid of the implied do saves about as many. Seems roughly a wash.

One caveat in f90/f95 is that the character lengths all need to be
padded to be the same with this form, which is a bit of a nuisance.
Because of that, I usually would not use this form myself. I'd probably
stick with the data statement for the character part. In f2003, you
could add the characvter length to the array constructor, though that's
a bit wordy (like this reply).

Now none of the above keep the name and corresponding data physically
adjacent in the source code. It occurs to be that might be what you mean
by "compact". It isn't what I'd normally consider "compact" to mean, but
it is a desireable feature of the data statement form above. One might
do that with an array of structures instead of two separate arrays,
though the form to write that as a literal constructor gets awfully
wordy.

Heh, yea, I was thinking something like:
mattabnm = (/'h ', 'd ', ... /)
mattabs = reshape( (/ #### , #### , ...
#### , #### , ...

What I meant by compact was could they be kept in a single statement. Having them physically next to each other, though, might be more important for readability, and as for data statements, I can't use them in this situation.

Thanks for the input.
.



Relevant Pages

  • Re: 77 to 90/95 assignment question.
    ... I'm not quite sure what you mean by "compact" in this case. ... most obvious translation to an assignment statement (and note that the ... I've also assumed that the arrays ... One caveat in f90/f95 is that the character lengths all need to be ...
    (comp.lang.fortran)
  • Re: index ... for max length
    ... It's 100 bytes for a non compact index or 240 bytes for a compact ... If the collating sequence is set to MACHINE, each character uses one ... If the indexed field supports null values, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Aerojet to develop 600kW Hall thruster
    ... > arrays don't come cheap or compact. ... Could it be that it's part of Prometheus? ...
    (sci.space.policy)
  • Re: sorting an array with associated values in separate arrays
    ... I have the following arrays, each with the same number of elements. ... mainhash by value, and keep the sorted keys for use in %bhash, etc.. ... Another, possibly simpler way would be to compact the separate arrays into a single, two-dimensional array and sort that: ... foreach my $pos { ...
    (comp.lang.perl.misc)
  • Re: 77 to 90/95 assignment question.
    ... assignment statement in f90/95 that is just as compact? ... This seems to be both elegant and easy to read and check - what more ... numbers in column 6 to indicate a continuation statement (zero is not ...
    (comp.lang.fortran)