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

Home » Public Forums » archive » Calling vectors in readcol from a string array?
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
Calling vectors in readcol from a string array? [message #85124] Mon, 08 July 2013 09:37 Go to next message
pslough93 is currently offline  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 Go to previous messageGo to next message
wlandsman is currently offline  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 Go to previous messageGo to next message
pslough93 is currently offline  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.
Re: Calling vectors in readcol from a string array? [message #85129 is a reply to message #85124] Mon, 08 July 2013 23:43 Go to previous message
Rob Klooster is currently offline  Rob Klooster
Messages: 18
Registered: February 2013
Junior Member
Replace the single quotes inside the string with 2x single quotes.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Widget_Table set_value interrupts editing. Solution needed.
Next Topic: "OPENW: Error opening file. Unit: (...) Too many links" - What does this mean? (Possible I/O problem)

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

Current Time: Wed Oct 08 13:48:21 PDT 2025

Total time taken to generate the page: 0.00467 seconds