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 #87711 is a reply to message #87707] Mon, 24 February 2014 20:04 Go to previous messageGo to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Hi folks,

If an extra copy of the strings will fit in memory, this might be easier:

f = 'test_string.txt'
strs = StrArr(File_Lines(f))
OpenR, unit, f, /Get_LUN
ReadF, unit, strs
Free_LUN, unit
strList = List(strs, /EXTRACT)

--

Cheers,
-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada
www.d-jackson.com

Paul van Delst wrote, On 2014-02-24, 9:20am:
> 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: Wed Oct 08 19:27:55 PDT 2025

Total time taken to generate the page: 0.00189 seconds