From: jshine on
I'm curious if anyone has some example code of how to input a 2-D (or,
in principle, n-D) array via a namelist file in Fortran 95 (I'm using
a reasonably current "gfortran" compiler)? I can load a 1-D array (a
vector) easily enough and have tried a number of permutations on that
syntax, but I haven't been successful yet. ...nor have I found any
good examples of this via Google or in any of my Fortran books.

Any help will be appreciated!

Thanks,
-Jon
From: Richard Maine on
jshine <jtomshine(a)gmail.com> wrote:

> I'm curious if anyone has some example code of how to input a 2-D (or,
> in principle, n-D) array via a namelist file in Fortran 95 (I'm using
> a reasonably current "gfortran" compiler)? I can load a 1-D array (a
> vector) easily enough and have tried a number of permutations on that
> syntax, but I haven't been successful yet. ...nor have I found any
> good examples of this via Google or in any of my Fortran books.

You input the elements in array sequence order, as in

x = 1,2,3,4

which, for an x dimensioned 2x2, gets you the array

1 3
2 4

You do have to understand array sequence order. There is no explicit
separation of rows/columns. Nor is there any kind of slice notation.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: glen herrmannsfeldt on
Richard Maine <nospam(a)see.signature> wrote:
> jshine <jtomshine(a)gmail.com> wrote:

>> I'm curious if anyone has some example code of how to input a 2-D (or,
>> in principle, n-D) array via a namelist file in Fortran 95 (I'm using
>> a reasonably current "gfortran" compiler)? I can load a 1-D array (a
>> vector) easily enough and have tried a number of permutations on that
>> syntax, but I haven't been successful yet. ...nor have I found any
>> good examples of this via Google or in any of my Fortran books.

> You input the elements in array sequence order, as in

> x = 1,2,3,4

> which, for an x dimensioned 2x2, gets you the array

> 1 3
> 2 4

> You do have to understand array sequence order. There is no explicit
> separation of rows/columns. Nor is there any kind of slice notation.

It seems that for F2003 (10.10.1.1) that subscripts, strides,
and substring expressions are allowed. The example given uses:

&TODAY I = 12345, X(1) = 12345, X(3:4) = 2*1.5, I=6, ! This is a comment.
P = ..ISN.T_BOB.S.., Z = (123,0)/

(It might wrap when I post it, but the comment should be on the end
of the first line.)

If an array name or structure is used then a list of elements
not longer than needed to fill the given array/structure is
allowed (as Richard indicated). Multipliers can be used in
place of repeated constants. The example is a shorter form of:

X(3:4)= 1.5, 1.5, or of X(3)=1.5, X(4)=1.5,

One that seems not to be allowed is vector subscripts.

Also, null elements (commas without any value in between) are
allowed, as are null elements with a multiplier. (Useful for
filling parts of a large array.)

-- glen

From: Ron Shepard on
In article <1jcm55s.1gyb0g61fu8gvcN%nospam(a)see.signature>,
nospam(a)see.signature (Richard Maine) wrote:

> jshine <jtomshine(a)gmail.com> wrote:
>
> > I'm curious if anyone has some example code of how to input a 2-D (or,
> > in principle, n-D) array via a namelist file in Fortran 95 (I'm using
> > a reasonably current "gfortran" compiler)? I can load a 1-D array (a
> > vector) easily enough and have tried a number of permutations on that
> > syntax, but I haven't been successful yet. ...nor have I found any
> > good examples of this via Google or in any of my Fortran books.
>
> You input the elements in array sequence order, as in
>
> x = 1,2,3,4
>
> which, for an x dimensioned 2x2, gets you the array
>
> 1 3
> 2 4
>
> You do have to understand array sequence order. There is no explicit
> separation of rows/columns. Nor is there any kind of slice notation.

The above is correct (of course), but here is another answer. You can
use namelist write statements to write out the data, and in almost all
situations that output is in the correct format to be read by some
subsequent namelist read statement. I think this works also for user
defined data types.

I don't remember the exact situations now, but the exceptions to this
write/read symmetry involve character items with embedded spaces or
quote characters (',").

$.02 -Ron Shepard
From: Richard Maine on
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

> Richard Maine <nospam(a)see.signature> wrote:

> > Nor is there any kind of slice notation.
>
> It seems that for F2003 (10.10.1.1) that subscripts, strides,
> and substring expressions are allowed.

Oh, I had forgotten about that. (I pretty much stopped using namelist
myself at about the time it was standardized). Thanks for the
correction.

I was probably thinking about how you can't do things like x(k)=12345
because the k isn't available.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
 |  Next  |  Last
Pages: 1 2
Prev: Data Plotting Library DISLIN 10.0
Next: errata list