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

Home » Public Forums » archive » Re: Finding if a structure tag name is defined?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Finding if a structure tag name is defined? [message #36688] Wed, 15 October 2003 11:51
mvukovic is currently offline  mvukovic
Messages: 63
Registered: July 1998
Member
wmc@bas.ac.uk wrote in message news:<3f8bebd3@news.nwl.ac.uk>...
> I want to know if a given keyword has been passed down via _extra, so
> I said "if (n_elements(e.c_linestyle) ne 0)" which of course doesn't
> work because if it isn't there you can't say e.linestyle (bring on
> perl...). I can use tag names to get all the tags, then search through
> for a match, but that seems silly and ugly. What is the correct way
> to find if a given structure has a certain tag in it? (And why
> couldn't I find the answer buried within DF's site ;-)?
>
> -W.


You may find the following routine usefull. It uses regular
expression matching to check for matches.

You may off course, combine it with some of the type-checking routines
posted on this thread

Mirko

function WhereKwdLike,vsStringVector,sString,cFound,_extra=_extra
; function returns matches of String in String Vector. A match occurs
; when the string, of length N matches the first N characters of a
; vector element. This function mimics the behavior of IDL when it
; matches an incomplete keyword.

;; Use a regular expression match. We match the String vector against
;; the string regular expression. In the regular expression, ^
matches
;; the string beginning and .* will match any number of characters
viMatches=StRegEx(vsStringVector,'^'+sString+'.*',/Fold_Case , $
_extra=_extra)
viFound=where(viMatches eq 0,cFound)
return,viFound
end
Re: Finding if a structure tag name is defined? [message #36693 is a reply to message #36688] Tue, 14 October 2003 19:35 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
wmc@bas.ac.uk wrote:
> David Fanning <david@dfanning.com> wrote:
>
>> Reimar Bauer writes:
>>
>>> I often use is_tag to determine if a tag is in a structure
>
>> But, alas, you are still going to have to call IS_TAG
>> as many times as you have letters in your keyword, if
>> you hope to fish it out unambiguously. :-(
>
> Hmm, so, isn't that a flaw in IDL? Taking on board your
> well-reasonsed critique of (over)using _extra, it still seems
> quite reasonable to expect to be able to find if a given tag
> exists in a given structure, via a mechanism as simple as
> using n_elements to see if a given variable exist. IDL seems
> to make this simple task harder than it should be.
>
> (and anyway, looking at the pro, it only needs calling once).

I thought David's point was that searching for a tag in the _EXTRA
structure (which is a little harder than it should be in IDL, but not
all that onerous) is something you generally should not do, because it
becomes laborious if you want to support keyword abbreviation. And of
course you *do* want to handle keyword abbrevation, unless you want to
write documentation that says "IDL allows abbreviated keywords, except
in my routines".

If you aren't interested in a keyword in the current routine, bundle it
in an _EXTRA structure (or _REF_EXTRA hidden string-array thingy). If
you do, declare it explicitly.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Finding if a structure tag name is defined? [message #36695 is a reply to message #36693] Tue, 14 October 2003 15:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
William writes:

> Hmm, so, isn't that a flaw in IDL?

Oh, I don't get into criticising IDL. I just take
it as it comes and am grateful for it. :-)

> (and anyway, looking at the pro, it only needs calling once).

Ah, yes. I just looked at the procedure briefly and overlooked
this neat Reimer trick! Well done.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Finding if a structure tag name is defined? [message #36696 is a reply to message #36695] Tue, 14 October 2003 14:53 Go to previous message
wmconnolley is currently offline  wmconnolley
Messages: 106
Registered: November 2000
Senior Member
David Fanning <david@dfanning.com> wrote:
> Reimar Bauer writes:
>> I often use is_tag to determine if a tag is in a structure

OK, thanks, I'll give it a go.

> But, alas, you are still going to have to call IS_TAG
> as many times as you have letters in your keyword, if
> you hope to fish it out unambiguously. :-(

Hmm, so, isn't that a flaw in IDL? Taking on board your
well-reasonsed critique of (over)using _extra, it still seems
quite reasonable to expect to be able to find if a given tag
exists in a given structure, via a mechanism as simple as
using n_elements to see if a given variable exist. IDL seems
to make this simple task harder than it should be.

(and anyway, looking at the pro, it only needs calling once).

-W.

--
William M Connolley | wmc@bas.ac.uk | http://www.antarctica.ac.uk/met/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
I'm a .signature virus! copy me into your .signature file & help me spread!
Re: Finding if a structure tag name is defined? [message #36702 is a reply to message #36696] Tue, 14 October 2003 09:55 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Reimar Bauer writes:

> I often use is_tag to determine if a tag is in a structure
>
> ; PURPOSE:
> ; Test if tagname is defined
> ;
> ; CATEGORY:
> ; PROG_TOOLS/STRUCTURES
> ;
> ; CALLING SEQUENCE:
> ; Result=is_tag(structure,tagname)

But, alas, you are still going to have to call IS_TAG
as many times as you have letters in your keyword, if
you hope to fish it out unambiguously. :-(

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Finding if a structure tag name is defined? [message #36703 is a reply to message #36702] Tue, 14 October 2003 09:34 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
wmc@bas.ac.uk wrote:

> I want to know if a given keyword has been passed down via _extra, so
> I said "if (n_elements(e.c_linestyle) ne 0)" which of course doesn't
> work because if it isn't there you can't say e.linestyle (bring on
> perl...). I can use tag names to get all the tags, then search through
> for a match, but that seems silly and ugly. What is the correct way
> to find if a given structure has a certain tag in it? (And why
> couldn't I find the answer buried within DF's site ;-)?
>
> -W.
>

I often use is_tag to determine if a tag is in a structure

; PURPOSE:
; Test if tagname is defined
;
; CATEGORY:
; PROG_TOOLS/STRUCTURES
;
; CALLING SEQUENCE:
; Result=is_tag(structure,tagname)

http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/is_tag_dbase.pro.html

regards

Reimar

--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
Re: Finding if a structure tag name is defined? [message #36706 is a reply to message #36703] Tue, 14 October 2003 07:32 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
William writes:

> I want to know if a given keyword has been passed down via _extra, so
> I said "if (n_elements(e.c_linestyle) ne 0)" which of course doesn't
> work because if it isn't there you can't say e.linestyle (bring on
> perl...). I can use tag names to get all the tags, then search through
> for a match, but that seems silly and ugly. What is the correct way
> to find if a given structure has a certain tag in it? (And why
> couldn't I find the answer buried within DF's site ;-)?

_EXTRA is often a great convenience (and maybe even
a miracle when you are writing object programs), but
is should NOT be used to collect keywords you care
about (at least not in the way you appear to be using it
here). In fact, I'm adding a rule to Coyote's List of Rules
You Violate Only If You Wish Your Program to Break at the
Most Inopportune Moment:

Rule 3495: If you care about a keyword, be sure
*you* define it somewhere!

Consider the PLOT command. It has 50-60 different keywords
that can be used with it. But if you are writing some
kind of wrapper to the PLOT command that uses a nifty
new plot symbol, you could care less about 49-59 of those
keywords. But you care desperately about the PSYM keyword.
In that case, you MUST define a PSYM keyword for your
program.

It is not fair to write this program and then decide
later than you really care about the LINESTYLE keyword,
too, and decide to fish it out of the _EXTRA structure.
(And what a nightmare, since you will have to look for
*all* possible spellings of LINESTYLE!) If you care
about it, you define it. Period. :-)

All those other keywords can be collected easily and
simply with _EXTRA. It is a convenience. (And also,
occasionally, a pain in the neck. Maybe you really
want to use _STRICT_EXTRA instead. Think about it.)

_EXTRA gives you more time to go drink coffee. But it doesn't
take away the responsibility of being a conscientious
programmer. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: What does an optimal scientific programming language/environment need?
Next Topic: efficient polynomial fitting

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

Current Time: Wed Oct 08 15:12:54 PDT 2025

Total time taken to generate the page: 0.00478 seconds