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

Home » Public Forums » archive » Re: Beginner fails miserabley at first hurdle 0.05 0.05
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: Beginner fails miserabley at first hurdle 0.05 0.05 [message #10898] Fri, 06 February 1998 00:00
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
clovis21@hotmail.com wrote:
>
> Hello all, I'm just starting, but I've come unstuck already. I'm
> trying to write a for .. do begin line, but I can't seem to get it to
> work:
>
> for i=0, 31 do $
> for k=0, 31 do $
> for j=0, 255 DO BEGIN
> real_b(i, k, j)=b(i, k, 2*j)
> imag_b(i, k, j)=b(i, k, (2*j)+1)
> print, i, k, j
> endfor
>
> In desperation I've tried the following:
>
> for i=1, 100 do begin
> print, i
> endfor
>
> and all that happens is that I get 101 printed, then a syntax error on
> the 'n' of endfor. What have I done wrong?
>
> Martin

Martin -

Hang in there man! Since IDL is interpreted line-by-line as you
enter commands, you can't enter loop constructs like you tried,
because those kinds of statements need to be *compiled*. To enter
these commands at the IDL prompt:

IDL> .run
- for i=1,100 do begin
- print, i
- endfor
- end

and you will get what you expect. Or you can do it on one line:

IDL> for i=1,100 do print, i

If you enter your commands like these examples, or put them into
a properly written .pro file and compile them, your statements
will work just fine:

; test.pro
PRO test, real_b, imag_b, b

for i=0, 31 do $
for k=0, 31 do $
for j=0, 255 DO BEGIN
real_b(i, k, j)=b(i, k, 2*j)
imag_b(i, k, j)=b(i, k, (2*j)+1)
print, i, k, j
endfor
return
end


Hope this helps.

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
Re: Beginner fails miserabley at first hurdle 0.05 0.05 [message #10925 is a reply to message #10898] Tue, 03 February 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Martin writes:

> Hello all, I'm just starting, but I've come unstuck already. I'm
> trying to write a for .. do begin line, but I can't seem to get it to
> work:
>
> for i=0, 31 do $
> for k=0, 31 do $
> for j=0, 255 DO BEGIN
> real_b(i, k, j)=b(i, k, 2*j)
> imag_b(i, k, j)=b(i, k, (2*j)+1)
> print, i, k, j
> endfor
>
> In desperation I've tried the following:
>
> for i=1, 100 do begin
> print, i
> endfor
>
> and all that happens is that I get 101 printed, then a syntax error on
> the 'n' of endfor. What have I done wrong?

There is nothing wrong with either of these code fragments.
The problem is probably that you are trying to type this code
at the IDL command line, and that is really hard to do with
multi-line code such as FOR loops.

Put this code into a text file. Add and extra END statement
at the bottom of everything else, save the file as "junk.pro"
(my favorite name), and then when you want to execute the code
type this:

IDL> .Run junk

It will all work as you expect it to. You have made what is
called a main-level IDL program. If you want to run the code
over again, you can type this:

IDL> .Go

If you get really desperate, you may want to have a look
at my IDL Programming Techniques book. This whole business
of writing programs is explained quite extensively. You can
learn more about the book on my web page.

Cheers,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: vector plots on maps
Next Topic: Re: Q: debuggging widget applications in IDL 5

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

Current Time: Sun Oct 12 04:52:22 PDT 2025

Total time taken to generate the page: 0.80082 seconds