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

Home » Public Forums » archive » error in a simple pro
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
error in a simple pro [message #55786] Wed, 12 September 2007 16:46 Go to next message
yychongzi is currently offline  yychongzi
Messages: 6
Registered: September 2007
Junior Member
Hi, I am new to ENVI and IDL, but really interested and trying to
learn.

Below is a simple pro file for reading ENVI image, but there is
something wrong with the line 'for i=0, .....' Could anyone tell me
why? Thanks a lot.


pro readenvi

envi_select, title='choose image', fid=fid, dims=dims, pos=pos
if(fid eq -1) then begin print, 'cancelled'
return
endif

envi_file_query, fid, fname = 'C:\ars\data\test'

num_cols = dims[2] - dims[1] + 1
num_rows = dims[4] - dims[3] + 1
num_bands = n_elements(pos)

image = fltarr(num_bands,num_cols,num_rows)

for i=0, num_bands -1 do image[i,*,*] = envi_get_data (fid=fid,
dims=dims, pos = pos[i])

window, 11, xsize=num_cols, ysize=num_rows, title = fname
tvscl, image[0,*,*]

print, num_cols
end
Re: error in a simple pro [message #55912 is a reply to message #55786] Thu, 13 September 2007 21:13 Go to previous message
yychongzi is currently offline  yychongzi
Messages: 6
Registered: September 2007
Junior Member
It runs after adding the following tow lines:

envi, /restore_base_save_files
envi_init, /batch_mode

---
Thanks



On Sep 13, 5:56 pm, yychon...@gmail.com wrote:
> I am surprised that Mort Canty replied to my question. Yes, the
> program is the first example in your book! And Dr. Fanning, I am
> reading your book too!
>
> Problem not solved.
> I put all the files (pro and ENVI data) on the IDL path, and added two
> lines:
>
> COMPILE_OPT idl2
> FORWARD_FUNCTION envi_select, ENVI_GET_DATA,envi_file_query
>
> The 'ENVI_GET_DATA' turned into different color, I guess IDL knows
> about it, but I got an error message:
> Attempt to call undefined procedure/function: 'ENVI_SELECT'.
> Actually when I tried to remove the for statement, I got the same
> message as above. If I removed the envi-select, then envi_file_query
> is the problem.
>
> Fanning, thanks for pointing out the IDL path. I found IDL sometimes
> only runs the old file for me, that is the reason.
> Mort, I did not forget the '$', I wrote the statement into one line.
> And 'fhame=fname ' won't work either.
>
> Thanks a lot for your time to help a newbie ^_^
Re: error in a simple pro [message #55913 is a reply to message #55786] Thu, 13 September 2007 17:56 Go to previous message
yychongzi is currently offline  yychongzi
Messages: 6
Registered: September 2007
Junior Member
I am surprised that Mort Canty replied to my question. Yes, the
program is the first example in your book! And Dr. Fanning, I am
reading your book too!

Problem not solved.
I put all the files (pro and ENVI data) on the IDL path, and added two
lines:

COMPILE_OPT idl2
FORWARD_FUNCTION envi_select, ENVI_GET_DATA,envi_file_query


The 'ENVI_GET_DATA' turned into different color, I guess IDL knows
about it, but I got an error message:
Attempt to call undefined procedure/function: 'ENVI_SELECT'.
Actually when I tried to remove the for statement, I got the same
message as above. If I removed the envi-select, then envi_file_query
is the problem.

Fanning, thanks for pointing out the IDL path. I found IDL sometimes
only runs the old file for me, that is the reason.
Mort, I did not forget the '$', I wrote the statement into one line.
And 'fhame=fname ' won't work either.


Thanks a lot for your time to help a newbie ^_^
Re: error in a simple pro [message #55932 is a reply to message #55786] Thu, 13 September 2007 05:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
mort canty writes:

> Runs OK for me (it should, since it's one of my examples :-) ).

I *thought* that code was pretty polished for a newbie. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: error in a simple pro [message #55933 is a reply to message #55786] Thu, 13 September 2007 02:10 Go to previous message
Mort Canty is currently offline  Mort Canty
Messages: 134
Registered: March 2003
Senior Member
yychongzi@gmail.com schrieb:
> Hi, I am new to ENVI and IDL, but really interested and trying to
> learn.
>
> Below is a simple pro file for reading ENVI image, but there is
> something wrong with the line 'for i=0, .....' Could anyone tell me
> why? Thanks a lot.
>
>
> pro readenvi
>
> envi_select, title='choose image', fid=fid, dims=dims, pos=pos
> if(fid eq -1) then begin print, 'cancelled'
> return
> endif
>
> envi_file_query, fid, fname = 'C:\ars\data\test'
>
> num_cols = dims[2] - dims[1] + 1
> num_rows = dims[4] - dims[3] + 1
> num_bands = n_elements(pos)
>
> image = fltarr(num_bands,num_cols,num_rows)
>
> for i=0, num_bands -1 do image[i,*,*] = envi_get_data (fid=fid,
> dims=dims, pos = pos[i])
>
> window, 11, xsize=num_cols, ysize=num_rows, title = fname
> tvscl, image[0,*,*]
>
> print, num_cols
> end
>

Runs OK for me (it should, since it's one of my examples :-) ). Did you
by any chance forget the $ in the first line of your FOR statement? The
keyword FNAME in ENVI_FILE_QUERY is for output by the way, so you should
write

ENVI_FILE_QUERY, fid, fname=fname

Cheers,

Mort
Re: error in a simple pro [message #55934 is a reply to message #55786] Wed, 12 September 2007 20:30 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
yychongzi@gmail.com writes:

> Below is a simple pro file for reading ENVI image, but there is
> something wrong with the line 'for i=0, .....' Could anyone tell me
> why?

I am going to presume you are having trouble compiling this
file, with IDL reporting a syntax error. This sheds some
light on a couple of things I have noticed from time to time,
that I am certain is not how IDL used to work. (I would
test it, but a couple of weeks ago, in an effort to get
more work out of an old machine, I deleted all my old
IDL versions.)

Here is what I think is happening. You don't have
the file ENVI_GET_DATA on your IDL path. Thus, when you
go to compile this file, this line causes a syntax error:

for I=0, num_bands -1 do image[I,*,*] = $
envi_get_data (fid=fid, dims=dims, pos = pos[I])

The problem is this. IDL can't find ENVI_GET_DATA on
your path, so it thinks ENVI_GET_DATA is a variable,
not a function call. This then *is* the wrong IDL syntax
for a variable, and IDL complains about it. Correctly, I think.

There are a couple of things you can do to get the file
compiled.

(1) Make sure the ENVI files are on your IDL path before
you try to compile ENVI functions. This is a good idea,
since even if the file compiles, it won't run unless
this happens.

(2) Add this line at the start of your program, so IDL
knows it is a function:

FORWARD_FUNCTION ENVI_GET_DATA

(3) Set the compiler option STRICTARR. (This is the best
solution in my opinion, and should be done in *all* your
IDL programs.)

COMPILE_OPT STRICTARR

Normally, you will see this written as this:

COMPILE_OPT idl2

which is just a short-hand way of getting STRICTARR
and DEFINT32 (long integers as the default, also a
good thing).

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ENVI File Question
Next Topic: insufficient system resources

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

Current Time: Wed Oct 08 18:36:36 PDT 2025

Total time taken to generate the page: 0.00591 seconds