Re: 77 to 90/95 assignment question.
- From: B <execrable@xxxxxxxxx>
- Date: Mon, 08 Dec 2008 21:29:29 -0700
Richard Maine wrote:
B <execrable@xxxxxxxxx> wrote:Heh, yea, I was thinking something like:
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.
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.
.
- References:
- 77 to 90/95 assignment question.
- From: B
- Re: 77 to 90/95 assignment question.
- From: Richard Maine
- 77 to 90/95 assignment question.
- Prev by Date: Re: St. Venants equation
- Next by Date: Re: St. Venants equation
- Previous by thread: Re: 77 to 90/95 assignment question.
- Next by thread: Re: 77 to 90/95 assignment question.
- Index(es):
Relevant Pages
|