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

Home » Public Forums » archive » Re: IDL 8.0 questions
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: IDL 8.0 questions [message #71822 is a reply to message #71821] Sat, 24 July 2010 23:07 Go to previous messageGo to previous message
Mike Potter is currently offline  Mike Potter
Messages: 19
Registered: August 2008
Junior Member
On Jul 24, 7:24 pm, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Jul 24, 1:18 pm, Mike Potter <m...@orionsound.com> wrote:
>
>
>
>
>
>> 1)  I'm trying out the new "foreach" capability.  The top loop, below,
>> works, the bottom one does not.
>
>> for i=0,nf-1 do begin
>>     qfile = file_names[i]
>>     image = readfits( qfile )
>>     sky,image,sky,sky_sig,/silent
>>     q = dialog_message( "Sky = "+string(sky)+"  Sigma =
>> "+string(sky_sig) ,/information )
>> endfor
>
>> foreach qfile, file_names do begin
>>     image = readfits( qfile )
>>     sky,image,sky_mod,sky_sig,/silent
>>     q = dialog_message( "Sky = "+string(sky_mod)+"  Sigma =
>> "+string(sky_sig) ,/information )
>> endforeach
>
>> After running the bottom loop, the first time readfits is called it
>> crashes and the input "qfile" has been changed and either contains two
>> characters equal to the final two characters of what qfile was on
>> input, or it returns a short string of garbage characters.
>> (file_names is a string array of filenames returned by
>> dialog_pickfile).
>
> I do not see why the second loop should not work the same as the
> first. I can only suggest to check the values in file_names before
> running each loop, or during the foreach loop, to make sure they are
> actually the same.- Hide quoted text -
>
> - Show quoted text -

Well, there's definitely something odd going on. Basically as long as
there is a "foreach" loop in the code some very strange things
happen. It may be some interaction with the AstroLib function
READFITS - I have the latest version downloaded just a couple of days
ago - shows last update as 7/16/2010. Note, though, I get similar
behavior using "FITS_READ" instead. It really seems to be an issue
with "FOREACH" loops.


Anyway, here's what happens:


I run the following code - selecting a group of 5 FITS files...

pro test_foreach,dummy
compile_opt IDL2

file_names = dialog_pickfile(filter="*.fit", path="E:\AstroData", /
read, /multiple_files )

print," "
for i=0,n_elements(file_names)-1 do begin
qfile = file_names[i]
print,strlen(qfile)
help,qfile
qim = readfits( qfile )
print,strlen(qfile)
help,qfile
endfor
end

All is well - here's the output:

IDL> test_foreach
% Compiled module: TEST_FOREACH.
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-045.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-045.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-041.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-041.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-042.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-042.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-043.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-043.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-044.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-044.fit'

IDL>



But - if I put in a "foreach" loop following the "for - next" loop:

pro test_foreach,dummy
compile_opt IDL2

file_names = dialog_pickfile(filter="*.fit", path="E:\AstroData", /
read, /multiple_files )

print," "
for i=0,n_elements(file_names)-1 do begin
qfile = file_names[i]
print,strlen(qfile)
help,qfile
qim = readfits( qfile )
print,strlen(qfile)
help,qfile
print," "
endfor

foreach qfile, file_names do begin
qim = readfits( qfile )
endforeach
end


I get the following output:

IDL> test_foreach
% Compiled module: TEST_FOREACH.

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-045.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-045.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-041.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-041.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-042.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-042.fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-043.fit'
% READFITS: Now reading 512 by 512 array
41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-043.fit'

41
QFILE STRING = '8 unsigned int, 16 & 32 int, -32 & -64
re'
% READFITS: ERROR - Unable to locate file 8 unsigned int, 16 & 32
int, -32 & -64 re
41
QFILE STRING = '8 unsigned int, 16 & 32 int, -32 & -64
re'

% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file re


A couple of things to note:

1) the final time through the first loop filenames get corrupted
somehow - and the string that results is actually some of the code
from "readfits.pro".

2) If I re-compile the exact same code for "test_foreach" I can get
different results -



IDL> test_foreach
% Compiled module: TEST_FOREACH.

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-045.fit'
% READFITS: ERROR - Unable to locate file fit
41
QFILE STRING = 'fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-041.fit'
% READFITS: ERROR - Unable to locate file fit
41
QFILE STRING = 'fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-042.fit'
% READFITS: ERROR - Unable to locate file fit
41
QFILE STRING = 'fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-043.fit'
% READFITS: ERROR - Unable to locate file fit
41
QFILE STRING = 'fit'

41
QFILE STRING = 'E:\AstroData\2010_03_0809B
\CR_Boo-044.fit'
% READFITS: ERROR - Unable to locate file fit
41
QFILE STRING = 'fit'

% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it
% READFITS: ERROR - Unable to locate file it



And - in this case, note that in the "FOR" loop, the "help,qfile" line
returns:

QFILE STRING = 'fit'

despite the fact that the line before that, "print,strlen(qfile)",
insists the string length is 41 characters.


Sorry this is such a long post - I guess maybe I should send this to
ITT VIS support? While editing I'm also getting frequent "freezes" of
the IDLDE and must use the task manager in windows to exit idl - or
the IDLDE just vanishes when I hit "compile". Is there any help in
the help files describing the IDLDE?

Thanks again for any insight..

Mike Potter
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Writing in IDL at the same line in the screen
Next Topic: Extract pixel values from HDF-EOS file

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

Current Time: Sat Oct 11 05:29:26 PDT 2025

Total time taken to generate the page: 0.16299 seconds