comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: turn a string value into variable name

Re: turn a string value into variable name
type: item
description: Nick writes: > I am restoring over 100 .sav files and creating structures for > analysis. Each .sav represents a differenct scenario and ideally I > would like to name the created structure in sequential format (case1, > case2...casen). > > To pull the data in I am using a for loop (all .sav have identical > array names) and I'd like to use the counter to name the variable. Is > it possible to turn a string into a variable name? The EXECUTE command can do this: FOR j=0,n DO BEGIN IF Execute('case' + String(j, Format='(I3.3)') + $ '= mysavedStruct') EQ 0 THEN $ Print, 'We have a failure to execute!' ENDFOR At one time there was a limit on the number of new variables that could be created this way inside an IDL program. I believe that limit has been removed. Cheers, David -- David Fanning, Ph.D. Coyote's Guide to IDL Programming (www.dfanning.com) Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2008-10-23T22:56:27-00:00

Re: turn a string value into variable name
type: item
description: Thank you very much David! Nick On Oct 23, 4:56 pm, David Fanning <n...@dfanning.com> wrote: > Nick writes: >> I am restoring over 100 .sav files and creating structures for >> analysis. Each .sav represents a differenct scenario and ideally I >> would like to name the created structure in sequential format (case1, >> case2...casen). > >> To pull the data in I am using a for loop (all .sav have identical >> array names) and I'd like to use the counter to name the variable. Is >> it possible to turn a string into a variable name? > > The EXECUTE command can do this: > > FOR j=0,n DO BEGIN > IF Execute('case' + String(j, Format='(I3.3)') + $ > '= mysavedStruct') EQ 0 THEN $ > Print, 'We have a failure to execute!' > ENDFOR > > At one time there was a limit on the number of new > variables that could be created this way inside an > IDL program. I believe that limit has been removed. > > Cheers, > > David > > -- > David Fanning, Ph.D. > Coyote's Guide to IDL Programming (www.dfanning.com) > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: Nick[2]
date: 2008-10-23T23:04:53-00:00

Re: turn a string value into variable name
type: item
description: That works, but wouldn't it be better to bring them into an array? Otherwise you'll meet the same problem when you want to calculate something with them.. scenario=ptrarr(n) for i=0,n-1 do begin ... scenario[i]=ptr_new(mySavedStruct) endfor ... DoSomething,*(scenario[j]) good luck, Greg
creator: greg.addr
date: 2008-10-24T13:08:37-00:00

Re: turn a string value into variable name
type: item
description: On 23 okt, 23:56, David Fanning <n...@dfanning.com> wrote: > Nick writes: >> I am restoring over 100 .sav files and creating structures for >> analysis. Each .sav represents a differenct scenario and ideally I >> would like to name the created structure in sequential format (case1, >> case2...casen). > >> To pull the data in I am using a for loop (all .sav have identical >> array names) and I'd like to use the counter to name the variable. Is >> it possible to turn a string into a variable name? > > The EXECUTE command can do this: > > FOR j=0,n DO BEGIN > IF Execute('case' + String(j, Format='(I3.3)') + $ > '= mysavedStruct') EQ 0 THEN $ > Print, 'We have a failure to execute!' > ENDFOR > > At one time there was a limit on the number of new > variables that could be created this way inside an > IDL program. I believe that limit has been removed. > > Cheers, > > David > > -- > David Fanning, Ph.D. > Coyote's Guide to IDL Programming (www.dfanning.com) > Sepore ma de ni thui. ("Perhaps thou speakest truth.") Thank you David, I had the same question !
creator: loebasboy
date: 2008-10-29T13:18:44-00:00

Re: turn a string value into variable name
type: item
description: 在 2008年10月24日星期五UTC+8上午6时56分27秒，David Fanning写道： > Nick writes: > >> I am restoring over 100 .sav files and creating structures for >> analysis. Each .sav represents a differenct scenario and ideally I >> would like to name the created structure in sequential format (case1, >> case2...casen). >> >> To pull the data in I am using a for loop (all .sav have identical >> array names) and I'd like to use the counter to name the variable. Is >> it possible to turn a string into a variable name? > > The EXECUTE command can do this: > > FOR j=0,n DO BEGIN > IF Execute('case' + String(j, Format='(I3.3)') + $ > '= mysavedStruct') EQ 0 THEN $ > Print, 'We have a failure to execute!' > ENDFOR it's helpful. thanks a lot > > At one time there was a limit on the number of new > variables that could be created this way inside an > IDL program. I believe that limit has been removed. > > Cheers, > > David > > -- > David Fanning, Ph.D. > Coyote's Guide to IDL Programming (www.dfanning.com) > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: sher.astro
date: 2012-12-06T09:55:17-00:00