m. Ooops. I just finished typing this whole thing and then noticed that
the subject line said f77. Almost all of my reply was about features new
to f90. I guess I'll go ahead and post it anyway, along with a short f77
answer and the suggestion that the OP consider moving to f90/f95.
To answer the original question in a pure f77 context, f77 basically has
no such thing as an array subsection, so you can't readily pass one.
There is a hack you can do for some cases, but it is really quite quirky
and only works at all for very limited cases.
The hack is that you pass an array element as the actual argument. Note
that the OP's a(,10) is not a proper syntax for an array element. THat
looks like an attempt at inventing a syntax for a section, but again,
f77 has no such thing. The syntax for the appropriate array element here
would be a(1,10).
Yes, the syntax is highly confusing and irregular in that there is no
way to tell by looking at it whether you are passing just that array
element or using this hack to pass what amounts to a section.
Anyway, if you pass an array element as an actual argument for an array
dummy argument, the dummy argument "gets" consecutive memory locations
starting with the specified element. You hav eto know about Fortran
array layout in memory in order to figure out what that means in any
particular case. Generally, it ends up meaning that this hack can be
used to pass an array column, but not to pass an array row.
So just changing your a(,10) to a(1,10) will probably do what you want.
But I recommend looking into f90/f95 instead. See below for that.
rjmagyar < XXXX@XXXXX.COM > wrote:
Well, there are 2 basic parts to it.
The first part is how to write a subsection of an array in any context.
This has nothing in particular to do with subroutines. I'm not 100% sure
what you mean by a(,10) above, as that is not a standard Fortran syntax
and you didn't explain what you intended, but I am reasonably confident
that what you meant was the 10th column of the array. That can be
written in any of several ways, the simplest of which is a(:,10). The
":" is the important part here; it indicates that there is a slice along
that dimension. You could more verbosely write a(1:10,10), explicitly
indicating the range of the slice, but the simple colon uses the
declared upper and lower bounds as defaults.
While this will work, it can have several undesired consequences.
1. Of course, if the actual argument ever has a size other than 10,
there will be problems. That might or might not be an isssue for your
2. This might trigger copy-in/copy-out in some cases with some
compilers. Basically, this f77-style (I'm ignoring the non-standard
real*8 bit) array declaration implies that the array is contiguous in
memory (like all f77 arrays are in practice). With array slices, you can
make non-contiguous actual arguments. The compiler is likely to make a
temporary contiguous copy to work around this.
I generally recommend declaring dummy arguments with assumed shape in
f90. That is, use the declaration form (again, I don't recommend the
real*8 part, but I'll copy your usage of that as it is not the main
This form says to get the array size from whatever is passed as the
actual argument. It also directly accomodates non-contiguous slices; the
information needed to deal with them is also passed from th eactual