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

Re: MAKE_ARRAY question



Craig Markwardt wrote:
> 
> Paul van Delst <paul.vandelst@noaa.gov> writes:
> 
> > Ben Tupper wrote:
> > >
> > > Hi Paul,
> > >
> > > X = MAKE_ARRAY( n_pts, TYPE = 4 + KEYWORD_SET(DOUBLE), /NOZERO)
> > >
> > > The above should get you the correct type of array (Double type is 5
> > > while Float type is 4.)
> >
> > True, but if double = 3 (in which case the keyword is also considered "set") the type
> > would be wrong (a string array!).
> 
> Huh?  So what if double EQ 3!  Vis:
> 
> IDL> print, keyword_set(1)
>        1
> IDL> print, keyword_set(2)
>        1
> IDL> print, keyword_set(3)
>        1
> 
> For KEYWORD_SET, I think "truth" is defined as non-zero.

Yep - you're right. I was mistakenly assuming that the keyword value evaluated the same
way as in the KEYWORD_SET true/false determination: even = false, odd = true, e.g.

IDL> if 1 then print, 'this is true'
this is true
IDL> if 2 then print, 'this is true'
IDL> if 3 then print, 'this is true'
this is true
IDL> 

But I was kwrong.


Liam sent me a solution I like the best:


  x = keyword_set(double) ? dblarr(npts, /nozero) : fltarr(npts, /nozero)


yay and cool bananas.

paulv

-- 
Paul van Delst           A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP        Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274  There shallow draughts intoxicate the brain,
Fax:(301)763-8545        And drinking largely sobers us again.
paul.vandelst@noaa.gov                   Alexander Pope.