comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Array multiplication: implicit loop query
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Array multiplication: implicit loop query [message #26186 is a reply to message #26185] Fri, 10 August 2001 05:58 Go to previous messageGo to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <d90c0773.0108100256.6398a693@posting.google.com>, george
Millward <george@apg.ph.ucl.ac.uk> wrote:

> Hi there
>
> I was just calculating the following equation:
>
> DEN_H = MMR_H * Pres * RMT / ( atomic_mass_H * Gas_constant * TN )
>
> These numbers are 3D arrays, 1D arrays and constants, i.e.,
>
> MMR_H = fltarr(30,91,40)
> Pres = fltarr(30)
> RMT = fltarr(30,91,40)
> atomic_mass_H = constant
> Gas_constant = constant
> TN =fltarr(30,91,40)
>
> The result of this is DEN_H (previously undefined) which ends up being
> fltarr(30) - i.e., 1 dimensional.
> To my mind DEN_H should be 3D (30,91,40) - shouldn't it ? Doesn't IDL
> understand that I am implicity doing a full 3D calculation here ?

No.

> It would seem that, to get this to work I need to make
> Pres=fltarr(30,91,40).

That's one solution. The other is to use loops.

FOR k = 0, 29 DO DEN_H[k,*,*] = MMR_H[k,*,*]*Pres[k]*RMT[k,*,*] / $
(atomic_mass_H* Gas_constant*TN[k,*,*])

This would be *much* more efficient (in terms of cache usage and array
indexing) if pressure was your last dimension, i.e.,

MMR_H = fltarr(91,40,30)
Pres = fltarr(30)
RMT = fltarr(91,40,30)
TN =fltarr(91,40,30)

Then you can write

FOR k = 0, 29 DO DEN_H[0,0,k] = MMR_H[*,*,k]*Pres[k]*RMT[*,*,k] / $
(atomic_mass_H*Gas_constant*TN[*,*,k])

The change in the indexing on the LHS to [0,0,k] is important.

Ken
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Log IDLgrAxis
Next Topic: Discussion on global variables in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 08:22:38 PDT 2025

Total time taken to generate the page: 0.24478 seconds