[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: findgen([variable])



"Pavel A. Romashkin" wrote:
> 
> I am afraid FINDGEN can not take a vector for dimensions. What I would
> try is either using a vector
> 
> x = [5, 7]
> r = findgen(total(x))
> 
> which still would allow transparent indexing of R. If I really needed
> multi D arrays, I'd use EXECUTE and build a command string using
> dimensions of X:
> 
> x = [5, 7]
> com = 'r = findgen('
> for i =0, n_elements(x)-1 do com = com +'x['+string(i)+']'+ $
> string(44b*byte(i ne n_elements(x)-1) > 41b)
> i=execute(com)
> 
> EXECUTE is not cute, but I can't come up with anything nicer. I need
> another cup of coffe :-(

Oof!

What about

IDL> x=[5,7]
IDL> ndim=n_elements(x)
IDL> n=1L 
IDL> for i=0,ndim-1 do n=n*x[i]
IDL> help, reform(findgen(n),x)
<Expression>    FLOAT     = Array[5, 7]
IDL> print, reform(findgen(n),x)
      0.00000      1.00000      2.00000      3.00000      4.00000
      5.00000      6.00000      7.00000      8.00000      9.00000
      10.0000      11.0000      12.0000      13.0000      14.0000
      15.0000      16.0000      17.0000      18.0000      19.0000
      20.0000      21.0000      22.0000      23.0000      24.0000
      25.0000      26.0000      27.0000      28.0000      29.0000
      30.0000      31.0000      32.0000      33.0000      34.0000

Seems that determining "n" is the hard part...is there a "PRODUCT" type of function in IDL? Like
TOTAL but with * rather than + as the operator.

Why doesn't MAKE_ARRAY allow for a dimension vector input?

paulv

-- 
Paul van Delst           Ph:  (301) 763-8000 x7274
CIMSS @ NOAA/NCEP        Fax: (301) 763-8545
Rm.207, 5200 Auth Rd.    Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746