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

Home » Public Forums » archive » AND statements
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
AND statements [message #14504] Sun, 28 February 1999 00:00 Go to next message
Phil Aldis is currently offline  Phil Aldis
Messages: 11
Registered: February 1999
Junior Member
Hi,
If you write some code like this:

test=Ptr_New()

IF Ptr_Valid(test) AND Size(*test, /type) NE 10 THEN print, *test

....can you always guarantee that it will not try to evaluate the second
statement if the first one was false - or is this a dangerous tactic to
adopt?

Oh, by the way, in a day or two I should be able to put out a little bit
of code which might be of interest to some. I did it at home so unlike
most of my programs I can let others use it. It will (hopefully) when
passed a pointer free up any heap memory, including, pointer arrays,
structures, objects. I suupose I could fairly simply extend it to object
references by simply using Obj_Class on the passed object reference,
then using Execute to create a structure and then it would be just like
normal. Although that addition might take a little while longer. If
anyone has any suggestions, please e-mail to let me know, (or if someone
else has done a program like this before).

Cheers,
Phil

P.S. If you reply, can you cc to philaldis@geocities.com, as well as to
the newsgroup, as my newsgroup feed seems to be more than a little
selective about the messages it picks up.
Re: AND statements [message #14532 is a reply to message #14504] Wed, 10 March 1999 00:00 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
rmlongfield@my-dejanews.com writes:
>
>
> Hi Jon, Please don't feel bad if you don't think people are using
> your programs. I've been hanging around this newsgroup for almost a year now
> and I've collected quite a lot of programs and web pages. Some I use, some
> not. I do use pointers frequently and even worse, pointers to pointers. When
> I've got a problem, I first search the Deja-News archives for this group for
> a solution. I may not use your program now but I did have a look at it and I
> know where it is for when and if I need it in the future.
>
> I do appreciate the sharing of tricks and ideas about how to
> handle certain problems.
> Rose

Here is what I have seen from my personal experience, based on my IDL
web page:

Number of IDL page hits per month - about 450
Number of program downloads per month - about 250
Number of feedback messages per month - about 1

So, to Phil: there may be a lot of people using your program but you
won't necessarily know about it. Feedback ratios seem to be less than
1%. Consider that: (a) only a fraction of people will download your
code; (b) a fraction of them will try to use it; (c) a fraction of
them will use it successfully; and (d) a fraction of them will then be
motivated to respond to the author.

Advertisement is also key. I see a noticeable increase in hits when I
mention my web page here on the newsgroup, based on informal polling.

To users of contributed software: feedback is always welcome! Whether
it's a bug report, a feature request, or a "thank you", I am sure that
the David's, Liam's, Phil's appreciate the interaction and knowing
that they don't live in a vacuum.

Craig

P.S. My IDL web page is http://astrog.physics.wisc.edu/~craigm/idl/idl.html
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: AND statements [message #14534 is a reply to message #14504] Wed, 10 March 1999 00:00 Go to previous messageGo to next message
philaldis is currently offline  philaldis
Messages: 32
Registered: March 1999
Member
On Wed, 10 Mar 1999 10:41:44 GMT, rmlongfield@my-dejanews.com wrote:

> Jon Kimber wrote:

Well, actually Phil Aldis wrote...but Phil Aldis also forgot to change
the signature file so that he was given the signature file that
someone else had been using.
>
> Hi Jon, Please don't feel bad if you don't think people are using
> your programs. I've been hanging around this newsgroup for almost a year now
> and I've collected quite a lot of programs and web pages. Some I use, some
> not. I do use pointers frequently and even worse, pointers to pointers. When
> I've got a problem, I first search the Deja-News archives for this group for
> a solution. I may not use your program now but I did have a look at it and I
> know where it is for when and if I need it in the future.
>
> I do appreciate the sharing of tricks and ideas about how to handle certain
> problems.
> Rose

Thank you, that makes me feel a bit better anyway. Maybe I feel
spurred on to tackle the general pupose structure editor now,
Cheers,
PHIL ALDIS
Re: AND statements [message #14535 is a reply to message #14504] Wed, 10 March 1999 00:00 Go to previous messageGo to next message
rmlongfield is currently offline  rmlongfield
Messages: 68
Registered: August 1998
Member
Jon Kimber wrote:
> I think that is certainly better than a goto in that circumstance. I
> had to use that several times in the ptr_free program I wrote (see
> post of 04/03/'99), but then no-one would know about that been as not
> one person has loooked at it - oh well I'll leave programs that are of
> use to others to the likes of DWF.
>
> Jon Kimber
> DERA
> ENGLAND
>

Hi Jon, Please don't feel bad if you don't think people are using
your programs. I've been hanging around this newsgroup for almost a year now
and I've collected quite a lot of programs and web pages. Some I use, some
not. I do use pointers frequently and even worse, pointers to pointers. When
I've got a problem, I first search the Deja-News archives for this group for
a solution. I may not use your program now but I did have a look at it and I
know where it is for when and if I need it in the future.

I do appreciate the sharing of tricks and ideas about how to handle certain
problems.
Rose

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Re: AND statements [message #14556 is a reply to message #14504] Tue, 09 March 1999 00:00 Go to previous messageGo to next message
philaldis is currently offline  philaldis
Messages: 32
Registered: March 1999
Member
I'll just post it again in case anyone was confused about the
signature. (different people using the same machine)

Martin Schultz <mgs@io.harvard.edu> wrote:

>> IF NOT (A EQ 0) THEN IF B/A GT 5 THEN <SOMETHING> $
>> ELSE <SOMETHING_ELSE> $
>> ELSE <SOMETHING_ELSE>
>>
>> (Where the second SOMETHING_ELSE is the same as the first one)
>>
>> [...]
>
> in short this is the same as
> IF E1 THEN ( IF E2 THEN A ELSE B ) ELSE C
>
> I don't think there are that many cases where B is really the same as C.

Well I've had it quite often when I've been dealing with pointers and
I want to find out if what a pointer points to is whatever, but ht
epointer might be null. I then obviously have to have a first test for
IF Ptr_Valid(pointer) THEN BEGIN
IF *pointer EQ whatever THEN BEGIN
.
.
.
.
ENDIF ELSE (carry out code for failed pointer)
ENDIF ELSE (carry out code for failed pointer)

The pointer failing due to it not been valid is the same kind of
failing as it not pointing to whatever so I have to either write code
twice or set a flag at (carry..) part and then do
IF flag EQ 1 THEN .... ,

I think that is certainly better than a goto in that circumstance. I
had to use that several times in the ptr_free program I wrote (see
post of 04/03/'99), but then no-one would know about that been as not
one person has loooked at it - oh well I'll leave programs that are of
use to others to the likes of DWF.


Cheers,
Phil
Re: AND statements [message #14557 is a reply to message #14504] Tue, 09 March 1999 00:00 Go to previous messageGo to next message
philaldis is currently offline  philaldis
Messages: 32
Registered: March 1999
Member
Martin Schultz <mgs@io.harvard.edu> wrote:

>> IF NOT (A EQ 0) THEN IF B/A GT 5 THEN <SOMETHING> $
>> ELSE <SOMETHING_ELSE> $
>> ELSE <SOMETHING_ELSE>
>>
>> (Where the second SOMETHING_ELSE is the same as the first one)
>>
>> [...]
>
> in short this is the same as
> IF E1 THEN ( IF E2 THEN A ELSE B ) ELSE C
>
> I don't think there are that many cases where B is really the same as C.

Well I've had it quite often when I've been dealing with pointers and
I want to find out if what a pointer points to is whatever, but ht
epointer might be null. I then obviously have to have a first test for
IF Ptr_Valid(pointer) THEN BEGIN
IF *pointer EQ whatever THEN BEGIN
.
.
.
.
ENDIF ELSE (carry out code for failed pointer)
ENDIF ELSE (carry out code for failed pointer)

The pointer failing due to it not been valid is the same kind of
failing as it not pointing to whatever so I have to either write code
twice or set a flag at (carry..) part and then do
IF flag EQ 1 THEN .... ,

I think that is certainly better than a goto in that circumstance. I
had to use that several times in the ptr_free program I wrote (see
post of 04/03/'99), but then no-one would know about that been as not
one person has loooked at it - oh well I'll leave programs that are of
use to others to the likes of DWF.



Jon Kimber
DERA
ENGLAND
Re: AND statements [message #14571 is a reply to message #14504] Mon, 08 March 1999 00:00 Go to previous messageGo to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Stein Vidar Hagfors Haugan wrote:
>
>
> True. The "problem" is when you want to write this up into
> a short and concise test with an ELSE part, you'll have to
> repeat the ELSE branch:
>
> IF NOT (A EQ 0) THEN IF B/A GT 5 THEN <SOMETHING> $
> ELSE <SOMETHING_ELSE> $
> ELSE <SOMETHING_ELSE>
>
> (Where the second SOMETHING_ELSE is the same as the first one)
>
> [...]

in short this is the same as
IF E1 THEN ( IF E2 THEN A ELSE B ) ELSE C

I don't think there are that many cases where B is really the same as C.
If so,
I find it often in error checking (is there a filename? is it empty?
etc.). In
these cases, it is often useful to "invert" the above to e.g.

IF NOT E1 THEN RETURN
IF E2 THEN A ELSE B

Shame on me(?), but sometimes I even think of and use GOTO statements in
similar
constructs. For skipping large convoluted IF THEN ELSE IF THEN ELSE
ENDIF IF ...
blocks, they are sometimes much more readable.

But it is true that I have often wished IDL had the abbreviated IF
clause. In my experience this is so common in modern computer languages
that it is rather dangerous *not* to have it available.

Regards,
Martin.

--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
Re: AND statements [message #14577 is a reply to message #14504] Sat, 06 March 1999 00:00 Go to previous messageGo to next message
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
In article <O0s$q03Z#GA.227@nih2naae.prod2.compuserve.com>
"Steve Scheele" <sscheele@scitor.com> writes:

> I wrote the previous message late at night - it really wasn't what I was
> thinking. I think that compound AND statements can be concisely written as;
>
> If Not (A EQ 0) Then If B/A GT 5 Then . . .
>
> Formed in this manner, the second part will not be evaluated is the first
> part is false.

True. The "problem" is when you want to write this up into
a short and concise test with an ELSE part, you'll have to
repeat the ELSE branch:

IF NOT (A EQ 0) THEN IF B/A GT 5 THEN <SOMETHING> $
ELSE <SOMETHING_ELSE> $
ELSE <SOMETHING_ELSE>

(Where the second SOMETHING_ELSE is the same as the first one)

The ?: construct gives a more compact notation:

IF ((A EQ 0) ? 0b : B/A GT 5) THEN <SOMETHING> $
ELSE <SOMETHING_ELSE>

Personally, though, I don't like using the ?: construct
for anything but assignments, since it tends to clutter
up more complex statements..

> The problem that I have is with the OR statement. Something
> like
>
> If A EQ 0 OR B/A GT 5
>
> will blow up on A=0
>
> I haven't really figured out a good way to implement this type of OR
> statement.

IF (A EQ 0) ? 1b : B/A GT 5 THEN ...

But again, this isn't very readable...

Stein Vidar
Re: AND statements [message #14590 is a reply to message #14504] Fri, 12 March 1999 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Kirmanta de Malher <fernandez-j2@chu-caen.fr> writes:
>
> Craig Markwardt wrote:
>
>> To users of contributed software: feedback is always welcome! Whether
>> it's a bug report, a feature request, or a "thank you", I am sure that
>> the David's, Liam's, Phil's appreciate the interaction and knowing
>> that they don't live in a vacuum.
>>
>>
>
> Oh well Craig, i thank you again for your programs. Do you plan to compile your
> mpfit program in C ? I would want to have more speed :) Bye, Jesus
>

Hmmm. I translated the curve-fitting program MPFIT from the fortran
package called MINPACK. There is also a C version available (check
Netlib). As for interfacing IDL and C, that gets a little sticky.
Since I use MPFIT, I'll certainly keep trying to improve it as I can,
including speeding it up.

Craig

P.S. MPFIT is available from
http://astrog.physics.wisc.edu/~craigm/idl/idl.html

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: AND statements [message #14592 is a reply to message #14504] Fri, 12 March 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Kirmanta de Malher (fernandez-j2@chu-caen.fr) writes:

>> To users of contributed software: feedback is always welcome! Whether
>> it's a bug report, a feature request, or a "thank you", I am sure that
>> the David's, Liam's, Phil's appreciate the interaction and knowing
>> that they don't live in a vacuum.
>
> Oh well Craig, i thank you again for your programs. Do you plan to compile your
> mpfit program in C ? I would want to have more speed :)

Well, now. Here is why feedback is a double-edged sword. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: AND statements [message #14594 is a reply to message #14504] Fri, 12 March 1999 00:00 Go to previous message
Kirmanta de Malher is currently offline  Kirmanta de Malher
Messages: 5
Registered: March 1998
Junior Member
Craig Markwardt wrote:

> To users of contributed software: feedback is always welcome! Whether
> it's a bug report, a feature request, or a "thank you", I am sure that
> the David's, Liam's, Phil's appreciate the interaction and knowing
> that they don't live in a vacuum.
>
>

Oh well Craig, i thank you again for your programs. Do you plan to compile your
mpfit program in C ? I would want to have more speed :) Bye, Jesus

--

+--------------------------------------+
| |
| Jesus Fernandez |
| Unite IRM du CHU de Caen |
| Avenue de la cote de nacre |
| 14033 Caen |
| France |
| |
+--------------------------------------+
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Drag-Drop Possible in IDL5.2 ??
Next Topic: Re: XResources and menu mnemonics

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

Current Time: Wed Oct 08 15:13:09 PDT 2025

Total time taken to generate the page: 0.00637 seconds