Calling vectors in readcol from a string array? [message #85124] |
Mon, 08 July 2013 09:37  |
pslough93
Messages: 2 Registered: July 2013
|
Junior Member |
|
|
I would like to generate vector names using and put them in a string array, and then I need to call these vector titles in with the readcol command. Here is basically what I want:
vectorname1/vectorname2 are string arrays with the desired names of each vector spreadsheets is a string array of the file names of all of the spreadsheets I want to load in
For I = 0, n do begin
readcol, spreadsheets[I], vectorname1[I], vectorname2[I], format='x,d,x,x,d'
endfor
Plot, vectorname1_1, vectorname2_1
I have tried using the execute command (i.e. execute('readcol,' + spreadsheets[I] + ',' + vectorname1[I] + ',' ...) but IDL returns an error when it encounters the additional quotes in the format keyword.
Any Ideas?
|
|
|
Re: Calling vectors in readcol from a string array? [message #85125 is a reply to message #85124] |
Mon, 08 July 2013 13:51   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Monday, July 8, 2013 12:37:17 PM UTC-4, pslo...@gmail.com wrote:
>
> I have tried using the execute command (i.e. execute('readcol,' + spreadsheets[I] + ',' + vectorname1[I] + ',' ...) but IDL returns an error when it encounters the additional quotes in the format keyword.
>
I'm not sure I completely understand the question but here's a try.
Use double quotes for the format keyword so it won't be confused with the single quotes used for EXECUTE().
While you should be able to use EXECUTE(), it might be better to use SCOPE_VARFETCH() to create a new variable given its string name. The little program below prompts the user to create a variable name, and then assigns the output of READCOL into that named variable.
pro test
;Ask user to supply a variable name
vectorname = ''
read,'Enter Vector name: ',vectorname
; Use READCOL to read into a temporary variable
readcol,'test.dat',temp
;Assign temporary variable to user-supplied variable name
(scope_varfetch(vectorname,/enter)) = temporary(temp)
return
end
|
|
|
Re: Calling vectors in readcol from a string array? [message #85126 is a reply to message #85125] |
Mon, 08 July 2013 14:24   |
pslough93
Messages: 2 Registered: July 2013
|
Junior Member |
|
|
On Monday, July 8, 2013 3:51:22 PM UTC-5, wlandsman wrote:
> On Monday, July 8, 2013 12:37:17 PM UTC-4, pslo...@gmail.com wrote:
>
>
>
>>
>
>> I have tried using the execute command (i.e. execute('readcol,' + spreadsheets[I] + ',' + vectorname1[I] + ',' ...) but IDL returns an error when it encounters the additional quotes in the format keyword.
>
>>
>
> I'm not sure I completely understand the question but here's a try.
>
>
>
> Use double quotes for the format keyword so it won't be confused with the single quotes used for EXECUTE().
>
>
>
> While you should be able to use EXECUTE(), it might be better to use SCOPE_VARFETCH() to create a new variable given its string name. The little program below prompts the user to create a variable name, and then assigns the output of READCOL into that named variable.
>
>
>
> pro test
>
>
>
> ;Ask user to supply a variable name
>
> vectorname = ''
>
> read,'Enter Vector name: ',vectorname
>
>
>
> ; Use READCOL to read into a temporary variable
>
> readcol,'test.dat',temp
>
>
>
> ;Assign temporary variable to user-supplied variable name
>
> (scope_varfetch(vectorname,/enter)) = temporary(temp)
>
>
>
> return
>
> end
Thanks for alerting me to the double quotes thing. Using execute now works as intended.
|
|
|
|