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

Home » Public Forums » archive » Re: creating variables in a FOR loop
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: creating variables in a FOR loop [message #79107] Thu, 02 February 2012 12:12
JDS is currently offline  JDS
Messages: 94
Registered: March 2009
Member
If you really have a good reason for doing this (and I concur with David that it's probably not what you want), you can:

(scope_varfetch('im_'+strtrim(temp,2),/ENTER) = mrdfits(files[i],0,h)

This is preferable to using EXECUTE, as it will still work in the IDLVM (and is faster).

JD
Re: creating variables in a FOR loop [message #79111 is a reply to message #79107] Thu, 02 February 2012 08:13 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 2 fév, 16:17, wlandsman <wlands...@gmail.com> wrote:
> On Thursday, February 2, 2012 9:53:13 AM UTC-5, singlebinary wrote:
>> 5          'im_'+strtrim(temp,2) = mrdfits(files[i],0,h)
>
> This statement does not create a variable but creates a string containing for example "im_1".      You can convert a string to a variable with the execute statement
>
>     status = execute("im_" + strtrim(temp,2) + "= mrdfits(files[i],0,h)" )
>
> --Wayne

I rather guess that the compiler simply complains because your left
hand side does not contain a named variable. You cannot store in it,
whatever 'mrdfits' is doing.
Alx.
Re: creating variables in a FOR loop [message #79115 is a reply to message #79111] Thu, 02 February 2012 07:17 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Thursday, February 2, 2012 9:53:13 AM UTC-5, singlebinary wrote:

> 5 'im_'+strtrim(temp,2) = mrdfits(files[i],0,h)

This statement does not create a variable but creates a string containing for example "im_1". You can convert a string to a variable with the execute statement

status = execute("im_" + strtrim(temp,2) + "= mrdfits(files[i],0,h)" )

--Wayne
Re: creating variables in a FOR loop [message #79116 is a reply to message #79115] Thu, 02 February 2012 07:07 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
singlebinary writes:

> I would like to read in 6 files and associate 6 variables in which to
> store the information. In the code below, I like to create variables
> which names, "m_0, im_1 and so on. However, I get s 'Syntax error' in
> line 6. Please help! Thanks in advance.
>
> 1 PRO CCFs
> 2 files=file_search('*.fits')
> 3 FOR i = 0, n_elements(files)-1 DO BEGIN
> 4 temp = i
> 5 'im_'+strtrim(temp,2) = mrdfits(files[i],0,h)
> 6 ENDFOR
> 7
> 8 END

I know you *think* this is what you want to do,
but I seriously doubt it is *really* what you want
to do. I would probably use a pointer array (or list,
if you are using IDL 8) to store the images, especially
if they were not all the same size. (If they are
the same size, an array would be my first choice.)

FUNCTION CCFs
files=file_search('*.fits', Count=count)
images = PtrArr(count)
FOR i = 0, count-1 DO BEGIN
images[i] = Ptr_New(mrdfits(files[i],0,h))
ENDFOR
RETURN, images
END

ptr = CCFS()
cgImage, *ptr[3] ; To display the fourth image.

END


Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: creating variables in a FOR loop [message #79117 is a reply to message #79116] Thu, 02 February 2012 06:57 Go to previous message
Rohit Deshpande is currently offline  Rohit Deshpande
Messages: 6
Registered: June 2011
Junior Member
Sorry, I mean line 5 and not 6.

Thanks,

On Feb 2, 9:53 am, singlebinary <singlebin...@gmail.com> wrote:
> Hello All,
>
> I would like to read in 6 files and associate 6 variables in which to
> store the information. In the code below, I like to create variables
> which names, "m_0, im_1 and so on. However, I get s 'Syntax error' in
> line 6. Please help! Thanks in advance.
>
> 1    PRO CCFs
> 2           files=file_search('*.fits')
> 3           FOR i = 0, n_elements(files)-1 DO BEGIN
> 4               temp = i
> 5               'im_'+strtrim(temp,2) = mrdfits(files[i],0,h)
> 6           ENDFOR
> 7
> 8   END
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Coyote Library Update
Next Topic: ANOVA statistical analysis with IDL

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

Current Time: Wed Oct 08 14:00:09 PDT 2025

Total time taken to generate the page: 0.00429 seconds