Re: Efficient way to pass different shaped arrays?



In article <c5qdndEDAoKZkD7ZnZ2dnUVZ_u-dnZ2d@xxxxxxxxxxx>,
glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> wrote:
Peter wrote:

SUBROUTINE B(array)
REAL, DIMENSION(28,0:10001), INTENT(INOUT) :: array
....
Since Fortran doesn't have a conditional operator, it might be that
you could use a trick I saw once in a discussion about how NOT to
write Fortran code. Consider:

DO 1 I=1,100
DO 1 J=1,100
1 A(I,J)=(I/J)*(J/I)

Peter's INTENT(INOUT) shows that he isn't restricted to f77. In f95
I admit MERGE is not an operator, but it is a conditional function
useful for things like Glen's. Also, FORALL saves 2 lines, allowing

FORALL(I=1:100,J=1:100) A(I,J) = MERGE(1.0, 0.0, I==J)

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 5341 fax (+64)(4)463 5045
.



Relevant Pages

  • A neat trick to serialize arrays and hashes
    ... who thinks that my trick is "obvious to everyone but inexperienced ... hashes -- that is, it can pack and unpack arrays and hashes to and ... I might want to serialize @a into a string for the purpose of storing ... array into a string like so: ...
    (comp.lang.perl.misc)
  • Re: Sorting a nested array (table) (alphabetically)
    ... The size of the array IS the number of ... you want to sort just the data elements on some record field. ... Perl is NOT fortran. ... Lose any fortran code you have when ...
    (comp.lang.perl.misc)
  • Re: Passing a 2 dimensional array from fortran to c++
    ... > will allocate 100 contiguous float values, just like a Fortran array. ... pass x to a subroutine with a float** dummy argument. ... the same in the fortran code ...
    (comp.lang.fortran)
  • Re: Select Case Fallthrough
    ... glen herrmannsfeldt wrote ... Allowing the extra comma means not having to special case the ... initialization items and dimension the array appropriately. ... sort of nonsense to worry about as well. ...
    (comp.lang.fortran)
  • Re: Puzzle
    ... > pointers, and that would really be tricky... ... array may be unbounded. ... As stated (and with the constraints above), ... on a trick; I think a solution that does not rely on the trick is ...
    (comp.programming)