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

Re: indexing over structure tags



Randall Skelton wrote:
> 
> Thanks Tom... I did think of that.  However, in this particular case there
> is some merit in having the name of the structure be a useful and human
> readable tag.  Nobody would be happy trying to remember yet another
> arbitrary numbering scheme for molecules when they'd rather just type the
> name ;)  My suspicion is that there isn't an easy way to do what I want...

Maybe more context is needed to solve your problem .... the user of the code *shouldn't*
have to remember the (not so) arbitrary numbering scheme - the user would type in a
molecule name (or names). How your code deals with searching the human readable tagnames
is a different matter, no?

e.g.

  ; define the basic structure for each 
  sm_struc = {basic_struct, comment: ' ', values: fltarr(nlev)}
  
  ; define the large structure
  data = {big_struct, so4: sm_struc, co2: sm_struc, hcl: sm_struc}

  ; get the names of the tags
  names = tag_names(data)

so that names = [so4, co2, hcl].

Say the user requests data for 'so4' and 'hcl' so how about

  user_request = ['so4', 'hcl']
  n_requests = N_ELEMENTS( user_request )

  FOR i = 0, n_requests - 1 DO BEGIN
    tag_number = (WHERE( user_request[i] EQ names ))[0]  ; <-- assume this always succeeds
    data_to_get = data.(tag_number).values
    IF ( i EQ 0 ) THEN $
      data_to_return = data_to_get $
    ELSE $
      data_to_return = [ [ data_to_return ], [ data_to_get ] ]
  ENDFOR

  RETURN, data_to_return


or something like that? As it is above might not work for plucking out structures, but
that's a detail. So is the concatenation build of the data_to_return. Should be o.k. for
small arrays tho'.

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.