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

Home » Public Forums » archive » Using a text list to populate a LIST() in IDL
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: Using a text list to populate a LIST() in IDL [message #87707 is a reply to message #87693] Mon, 24 February 2014 09:20 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
I created a test file, "test_string.txt", that contains the following
(minus the "%<" lines):

-----%<-----
this is string one
and now string two
this little piggy cried wee wee wee...
the end
-----%<-----

Then the procedure:

-----%<-----
pro read_into_list, user_list
user_list = list()
openr, fid, "test_string.txt", /get_lun
cbuffer = ""
while (~ eof(fid)) do begin
readf, fid, cbuffer
user_list.add, cbuffer
endwhile
free_lun, fid
end
-----%<-----

Running the above in IDL:


IDL> .run read_into_list
% Compiled module: READ_INTO_LIST.
IDL> read_into_list, x
IDL> help, x
X LIST <ID=1 NELEMENTS=4>
IDL> for i=0, n_elements(x)-1 do help, x[i]
<Expression> STRING = 'this is string one'
<Expression> STRING = 'and now string two'
<Expression> STRING = 'this little piggy cried wee wee wee...'
<Expression> STRING = 'the end'

When I edit the file and run again I get

IDL> read_into_list, x
IDL> for i=0, n_elements(x)-1 do help, x[i]
<Expression> STRING = 'this is string one'
<Expression> STRING = 'and now string two'
<Expression> STRING = 'toss in a third string,'
<Expression> STRING = 'this little piggy cried wee wee wee...'
<Expression> STRING = 'the end'
<Expression> STRING = 'not really. This the the last line'


How's that?


cheers,

paulv

On 02/23/14 17:31, johnson.dustin.astro@gmail.com wrote:
> Hi,
>
>
> I am writing a function/routine that makes use of a user provided
> list
of strings. Right now, the user needs to edit the LIST(a,b,c,d)
parameter. I was wondering if there is a way for me to have the routine
reference a .txt file and use the contents to populate the list, rather
than have the user edit the function.
>
> Does anyone know how I would accomplish this?
>
> Thanks!
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to use IDL in a cronjob?
Next Topic: learning how to use mpfit,. need help

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

Current Time: Fri Oct 10 01:59:16 PDT 2025

Total time taken to generate the page: 0.12712 seconds