Hello;
1) Given arrays "xa" and "ya" of length "m" containing a tabulated
function, the following simplified/abbreviated code shows the 1st
call passing the first 3 elements of the arrays, while the 2nd call
passing the last 3 elements:
(F77, g95):
Program main
Parameter (m=30)
dimension xa(m), ya(m)
!.........my code1.........
Call DerivPol (xa, ya, 3, xa(1), d1)
Call DerivPol (xa(m-2), ya(m-2), 3, xa(m), dn)
!.........my code2.........
Stop
!*******************************************
Subroutine DerivPol (xa, ya, n, x, dy)
!*******************************************
c Given arrays xa and ya, each of length n, and given a value x,
c this routine returns a value dy.
Parameter (nmax=30)
dimension xa(n),ya(n),cof(nmax),pd(nmax)
!.........my code3.........
Return
End
2) The above 1st Call DerivPol() is OK. How about the 2nd call ??
Do you see any potential problem with the second call ??
3) Now, if the arrays "xa" and "ya" are 2D dimensioned "nmax,mmax" in
main and its routine, and the necessary declarations and changes to
the arguments are made accordingly to accommodate the additional
dimension.
One can easily (I think) modify the above 1st Call to pass a subarray,
say 4 (rows) by 3 (col) elements at the top left of the arrays.
But can one similarly extend the 2nd Call to pass a subarray 4 by 3 at
the bottom right of the arrays ??
My concern is primarily the conflict between matrix definition and the
arrays elements storage sequence!!
How would write the 2nd call in this 2D case ??
(I should be able to extend it to the 3D arrays case)
Your suggestions and advice would be greatly appreciated.
Monir
|
|
0
|
|
|
|
Reply
|
monirg (155)
|
11/16/2009 3:42:44 AM |
|
monir <monirg@mondenet.com> wrote:
> 1) Given arrays "xa" and "ya" of length "m" containing a tabulated
> function, the following simplified/abbreviated code shows the 1st
> call passing the first 3 elements of the arrays, while the 2nd call
> passing the last 3 elements:
> (F77, g95):
> Program main
> Parameter (m=30)
> dimension xa(m), ya(m)
> !.........my code1.........
> Call DerivPol (xa, ya, 3, xa(1), d1)
> Call DerivPol (xa(m-2), ya(m-2), 3, xa(m), dn)
> !.........my code2.........
> Stop
> !*******************************************
> Subroutine DerivPol (xa, ya, n, x, dy)
> !*******************************************
> c Given arrays xa and ya, each of length n, and given a value x,
> c this routine returns a value dy.
> Parameter (nmax=30)
> dimension xa(n),ya(n),cof(nmax),pd(nmax)
> !.........my code3.........
> Return
> End
> 2) The above 1st Call DerivPol() is OK. How about the 2nd call ??
> Do you see any potential problem with the second call ??
Looks fine to me. More usual, the dummy arrays would be
dimensioned (*) instead, but (n) might allow bounds checking
on the specified bounds. (Which may or may not match the actual
argument bounds.)
> 3) Now, if the arrays "xa" and "ya" are 2D dimensioned "nmax,mmax" in
> main and its routine, and the necessary declarations and changes to
> the arguments are made accordingly to accommodate the additional
> dimension.
> One can easily (I think) modify the above 1st Call to pass a subarray,
> say 4 (rows) by 3 (col) elements at the top left of the arrays.
If the elements are contiguous, yes. That would require all except
the rightmost subscript to be equal in the dummy and actual arguments.
> But can one similarly extend the 2nd Call to pass a subarray 4 by 3 at
> the bottom right of the arrays ??
Same requirements as for the top.
> My concern is primarily the conflict between matrix definition and the
> arrays elements storage sequence!!
> How would write the 2nd call in this 2D case ??
> (I should be able to extend it to the 3D arrays case)
Well, one way is to use assumed shape which can process non-contiguous
arrays fairly easily. (Though possibly slower due to cache effects.)
The Fortran 77 way is to pass both the actual dimension for all
except the rightmost, in addition to the subarray dimensions.
(Which still works in later versions as assumed size or explicit
size.)
-- glen
|
|
0
|
|
|
|
Reply
|
glen
|
11/16/2009 5:56:42 AM
|
|
On Nov 16, 12:56=A0am, glen herrmannsfeldt <g...@ugcs.caltech.edu>
wrote:
> monir <mon...@mondenet.com> wrote:
> - Show quoted text -
Glen;
Thank you for your prompt and helpful reply.
Regards.
Monir
|
|
0
|
|
|
|
Reply
|
monir
|
11/16/2009 2:12:33 PM
|
|
"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message news:hdqpiq$li6$1@naig.caltech.edu...
| monir <monirg@mondenet.com> wrote:
|
| > 1) Given arrays "xa" and "ya" of length "m" containing a tabulated
| > function, the following simplified/abbreviated code shows the 1st
| > call passing the first 3 elements of the arrays, while the 2nd call
| > passing the last 3 elements:
| > (F77, g95):
|
| > Program main
| > Parameter (m=30)
| > dimension xa(m), ya(m)
| > !.........my code1.........
| > Call DerivPol (xa, ya, 3, xa(1), d1)
| > Call DerivPol (xa(m-2), ya(m-2), 3, xa(m), dn)
|
| > !.........my code2.........
| > Stop
|
| > !*******************************************
| > Subroutine DerivPol (xa, ya, n, x, dy)
| > !*******************************************
| > c Given arrays xa and ya, each of length n, and given a value x,
| > c this routine returns a value dy.
|
| > Parameter (nmax=30)
| > dimension xa(n),ya(n),cof(nmax),pd(nmax)
| > !.........my code3.........
| > Return
| > End
|
| > 2) The above 1st Call DerivPol() is OK. How about the 2nd call ??
| > Do you see any potential problem with the second call ??
|
| Looks fine to me. More usual, the dummy arrays would be
| dimensioned (*) instead, but (n) might allow bounds checking
| on the specified bounds. (Which may or may not match the actual
| argument bounds.)
The purpose of not using (*) and instead of using (n)
for the bound is to enable PRINT *, xa, ya to work.
|
|
0
|
|
|
|
Reply
|
robin
|
11/17/2009 8:59:36 AM
|
|
On Nov 17, 3:59=A0am, "robin" <robi...@bigpond.com> wrote:
> "glen herrmannsfeldt" <g...@ugcs.caltech.edu> wrote in messagenews:hdqpiq=
$li6$1@naig.caltech.edu...
> | monir <mon...@mondenet.com> wrote:
> "robin" <robi...@bigpond.com> wrote:
> The purpose of not using (*) and instead of using (n)
> for the bound is to enable PRINT *, xa, ya to work.
Good point.
I generally try to avoid the use of (*) as a length specifier.
Besides, I don't think it can be used in multidimensional arrays, at
least in F77. Correct ??
Regards.
Monir
|
|
0
|
|
|
|
Reply
|
monir
|
11/17/2009 5:44:31 PM
|
|
monir <monirg@mondenet.com> wrote:
(snip)
> I generally try to avoid the use of (*) as a length specifier.
> Besides, I don't think it can be used in multidimensional arrays, at
> least in F77. Correct ??
The * can be specified for the last (rightmost) subscript of
a multidimension array. Also, the number of dimensions (rank)
does not have to agree with that of the actual argument.
-- glen
|
|
0
|
|
|
|
Reply
|
glen
|
11/17/2009 6:22:42 PM
|
|
On Nov 17, 1:22=A0pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> monir <mon...@mondenet.com> wrote:
>
> The * can be specified for the last (rightmost) subscript of
> a multidimension array. =A0Also, the number of dimensions (rank)
> does not have to agree with that of the actual argument.
>
Glen;
1) You raised an extremely interesting point, which might lead to the
solution of a problem I'm stuck with for quite some time now,
basically "suspected array distortion" somewhere in a (large and
complex) program and unable to locate exactly where!!
No compiler errors, no out-of-bound, no warnings, etc., just mixed
results for very simplified scenarios.
2) If I have arrays x(10,20,30) and y(5,25) passed as arguments to Sub
Test(xx,yy,...) and if I interpret your statement correctly regarding
the use of * and the no. of dimensions, then in Sub Test() any of the
following declarations, depending on the function of the sub, would be
acceptable: (F77, g95)
!...real xx(10,20)
!...real xx(10,20,*)
!...real yy(5,*)
!...real yy(5)
!...(others?)
Correct ??
3) If you concur, then I should be able to remove unnecessary
"rightmost" dim from similar declarations throughout the program or
replace them with *, as the case maybe, and thus narrow down the
search of arrays distortion.
Regards.
Monir
|
|
0
|
|
|
|
Reply
|
monir
|
11/17/2009 8:01:00 PM
|
|
In article <hdqpiq$li6$1@naig.caltech.edu>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> Well, one way is to use assumed shape which can process non-contiguous
> arrays fairly easily. (Though possibly slower due to cache effects.)
>
> The Fortran 77 way is to pass both the actual dimension for all
> except the rightmost, in addition to the subarray dimensions.
> (Which still works in later versions as assumed size or explicit
> size.)
The above "cache effect" comment applies equally to both situations.
That is, it is due to the effect of noncontiguous addressing on the
hardware rather than to the differences in the two features of the
language.
Also, on some compilers the assumed shape approach is more flexible.
For example, a TRANSPOSE() expression in an actual argument might be
done simply with dope vector manipulation rather than creating a copy,
while the f77 approach would always require an explicit copy. You can
verify this with the (nonstandard) loc() function; it surprised me the
first time I saw a compiler do this.
$.02 -Ron Shepard
|
|
0
|
|
|
|
Reply
|
Ron
|
11/17/2009 9:10:05 PM
|
|
|
7 Replies
128 Views
(page loaded in 0.102 seconds)
Similiar Articles: Difference between passing a number and a variable to a subroutine ...Number of points selected INTEGER(HID_T ... Elements coordinates ... way of passing an array by reference and > passing an array ... row-wise selection in a uitable - comp.soft-sys.matlab... m having is that once I turn on the non-contiguous cell ... to happen is (a) for the user to be able to select ... Every cell contains 10 elements array column wise. ... Neatest way to get the end pointer? - comp.lang.c... just past the end of an array does not. > > This is mentioned in passing in ... p is a two-dimensional array of elements ... For contiguous arrays, the only type in C, the ... SOLUTION: compile time array size using type only - comp.lang.c++ ...... when you have an actual array instance at hand, i.e. how N_ELEMENTS could be ... is determined when all you pass to the array_size ... comp.lang.c++.moderated ..... of contiguous ... nitializing a static vector <> of integers (this static vector... take the address of its first element, and pass that to a function expecting a C style array. ... does not explicitly require that the elements of a vector are contiguous, but ... Fastest way of partitioning an array based on a cutoff value ...... partition the array into two sub arrays a1 and a2, such that a2 contains only the elements ... How to select 1 record from 1M records ... Given a line variable L, pass the ... JTable - How To Loop Through Looking For Selected Rows? - comp ...... select specified columns in ch. array - comp ... that made a pass through ... How to transpose selected ... we want to select (x ... You have a point set P with elements ... Where did Fortran go? - comp.lang.fortran... which is likely), you could use few selected ... not others, > or it works when you pass in a column of an array ... of > the original, and necessarily contiguous, array ... syntax error "missing ; before statement" - comp.lang.javascript ...... var functionlist=new Array ... not quite sure why you're passing the same string to both, and if you're trying to create new option elements in an existing select ... Random number in Fortran 90/95 - comp.lang.fortran... may color my expectations for passing co-arrays to ... What I'm doing now is simply "select id f... ... to select specific column elements for each row of a numpy array ... Array data structure - Wikipedia, the free encyclopedia... are stored in an array, individual objects are selected by ... for the array, and is a convenient way to pass arrays as ... always created with contiguous elements, some array ... Arrays - C++ Documentation - cplusplus.com - The C++ Resources NetworkArrays An array is a series of elements of the same type placed in contiguous memory locations that can be ... At some moment we may need to pass an array to a ... 7/25/2012 5:30:02 PM
|