v087mxgb@ubvmsa.cc.buffalo.edu (Shawn E Thompson) (12/01/90)
Hi-ho all, thank you ALL for the overwhelming response I received in my previous posts....you were all VERY helpful..... I am in a little bind. I am trying to do the following and don't know if it is possible, please tell me ASAP; I have a main program and a subroutine (well much more than that, but this is a simplification). The main program runs some calc's and creates a matrix of numbers (say MxN). The subroutine needs one row at a time in array format (say Mx1). The subroutine cannot be restructured because of its impact on tons of other code. Short of rewriting the main prog., and common blocks don't offer an obvious answer..... can I send one column of a matrix into an array with a CALL statement, without passing the variables into a dummy array first (which is what I'll do as a last resort), sample code; PROGRAM MAIN REAL XMATRIX(10,20) . . . CALL SAMPLE(XMATRIX(???what goes here???) ) END SUBROUTINE SAMPLE(XARRAY) REAL XARRAY(20) . . . RETURN END THANK YOU IN ADVANCE!!!! *** MY OPINIONS *** (oops, capslocks) Yes, to answer a rhetorical question, there ARE people out here, in the REAL world who use and love Fortran - I'm just one. I wish someone would make a TURBO or QUICK style F77 compiler (like Quickbasic or TurboC)....then again, I haven't seen a new compiler in five years. Shawn E. Thompson "..my sig file was so long, I'm not even allowed a quote..." v087mxgb@ubvms.cc.buffalo.edu | set@autarch.acsu.buffalo.edu University @ Buffalo|Graduate School of Mechanical Engineering CAD Engineering|Leica, Inc.|PO Box 123|Buffalo, NY 14240-0123|(716)891-3375
silvert@cs.dal.ca (Bill Silvert) (12/03/90)
In article <48577@eerie.acsu.Buffalo.EDU> v087mxgb@ubvmsa.cc.buffalo.edu writes: > >I am in a little bind. I am trying to do the following >and don't know if it is possible, please tell me ASAP; > >I have a main program and a subroutine (well much more >than that, but this is a simplification). The main >program runs some calc's and creates a matrix of numbers >(say MxN). The subroutine needs one row at a time in >array format (say Mx1). The subroutine cannot be >restructured because of its impact on tons of other code. > >can I send one column of a matrix into an array with a >CALL statement, without passing the variables into a >dummy array first (which is what I'll do as a last resort), You refer to rows at one point and columns at another. It makes a big difference. Treating MxN as Mx1 is tricky, but 1xN is easy because of the way that Fortran stores arrays. To handle the mth column: real array(M, N) ... call proc(array(m, 1), N) ... subroutine proc(array, N) real array(1, N) ... should handle it, since the calling procedure passes the address of the first element of the column and the subroutine processes N values starting at the address passed. If you need to process rows, then you may be able to do the following: pass the address of array(1, n) to the subroutine, and have the subroutine process every Mth value in an array of length M*(N-1)+1. -- William Silvert, Habitat Ecology Division, Bedford Inst. of Oceanography P. O. Box 1006, Dartmouth, Nova Scotia, CANADA B2Y 4A2. Tel. (902)426-1577 UUCP=..!{uunet|watmath}!dalcs!biomel!bill BITNET=bill%biomel%dalcs@dalac InterNet=bill%biomel@cs.dal.ca
JRowe@exua.exeter.ac.uk (John Rowe) (12/05/90)
I think you're doomed on this one. As I understand it you have A(M,N) and you're trying to send A(J,1), A(J,2) ... A(J,N) to a subroutine as a one dimensional array (if you were trying to send A(1,I), A(2,I) .. A(M,I) that's easy but I'm sure you know that!). A one dimensional array consists of N contiguous values, ie ARRAY(K) is stored immediately after ARRAY(K-1) and immediately before ARRAY(K+1). Your 2-D array is stored as A(1,1), A(2,1), A(3,1) ... A(M,1), A(1,2), A(2,2), etc so you're trying to access every M'th value. I assume you can't conveniently reverse the order of A's subscripts in the main program (or get the compiler to do it for you) so I should take the simple but nasty way you sugested of creating a temporary array. You COULD recode your subroutine so that references to ARRAY(K) are replaced by ARRAY(1 + (K-1)*MLOCAL) where MLOCAL is either 1 or M; ie from: FUNCTION FRED(ARRAY) typical line: ARRAY(K) = REAL(K) to: FUNCTION FRED2(ARRAY,MLOCAL) typical line: ARRAY(1 + (K-1)*MLOCAL) = REAL(K) You can do this quite mechanically and be sure it will work (but see pedantic footnote below). You could even have a dummy routine FRED(ARRAY) which just calls FRED2(ARRAY,1) to avoid changing the rest of your code (or two entry points, aaarghh, no!). But it is very messy and probably slower to execute as well. Only consider something like this if: a) it is time critical and b) N is so large that it's time consuming to create a dummy array and c) you only access a small number of elements of ARRAY in FRED So do it your way. Sorry to be so unhelpful. Pedantic footnote? Well, if you do this and you want strict FORTRAN 77 compatibility you may need to change the size you declare ARRAY to be in FRED2 so that all the ARRAY(1 +(K-1)*MLOCAL)s don't overrun the size of ARRAY as declared in FRED2. But you'll probably get away without it. And FORTRAN v c? Well, we find our 'standard' matrix crunching codes don't need anything FORTRAN doesn't have but some of our more unusual codes do. But _EVERTHING_ needs complex numbers. You can't call c a suitable scientific/mathematical language if it doesn't even implement the entire number set. John Rowe Computational Physics Group Exeter University England
JRowe@exua.exeter.ac.uk (John Rowe) (12/05/90)
Re changing your subroutine to accept values from a two dimensional array. Oops! In my hurry to leave to get somewhere I forgot two minor points: First, obvious I know, but if you change the way you store an array in your subroutine it will work fine only if you also change anything else it calls as well, and anything associated with the array (ie anything equivalenced). Second, if you do this you may as well move the goal posts and make the array in your subprogram two dimensional, ie go from: FUNCTION FRED (ARRAY) to: FUNCTION FRED2(ARRAY2,MLOCAL) REAL ARRAY(N) REAL ARRAY2(MLOCAL,N) When the array is really one dimensional make MLOCAL 1, when it's two dimensional make MLOCAL it's first dimension. Then replace references to ARRAY(K) by ARRAY2(1,K). This is then entirely equivalent to my previous example and is called like this: RESULT = FRED2(A(J,1),M) which passes the Jth column of A to FRED2. Looks nicer and is preferable but _still_ messes up the way your data is stored and will still probably run slower. It all comes down to "IMHO, No, you can't do it, what you sugested was best." John Rowe Today's Corny moral: Never post when you're in a hurry to get somewhere.