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

Home » Public Forums » archive » Re: IDL input files.
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: IDL input files. [message #54525 is a reply to message #54524] Mon, 18 June 2007 12:15 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> ryanselk@gmail.com wrote:
>> ive been reading some manuals and books for IDL but im not sure how to
>> solve this likely simple problem.
>>
>> I have this I need to input to idl (.txt file):
>>
>> Name = {Joe}
>> Department = {CS}
>> Age = {25}
>>
>>
>> and in IDL i need to save each attribute to its own variable. But if,
>> lets day, department is ommited I want it to not input age as
>> department. With c/c++ this isnt so bad as you can search the file for
>> a 'keyword' and print the value from there, but I cant find how to do
>> this in IDL.
>
> Well, I don't think you can search the file in IDL, but you can read it in line by line
> and search the lines. Why not create the file as IDL commands? e.g.:
>
>
> ??
>
>
> IDL> .run test
> % Compiled module: TEST.
> IDL> test
> NAME STRING = 'Joe'
> DEPARTMENT STRING = 'CS'
> AGE INT = 25
>
> IDL> $more test.input
> Name = "Joe"
> Department = "CS"
> Age = 25

Well, I'd do this a little differently:

pro test, name, dept, age

; Create file to read
openw, lun, 'test.input', /get_lun
if n_elements(name) NE 0 then $
printf, lun, 'Name = ' + name else $
printf, lun, 'Name = '
if n_elements(dept) NE 0 then $
printf, lun, 'Department = ' + dept else $
printf, lun, 'Department = '
if n_elements(age) NE 0 then $
printf, lun, 'Age = ' + StrTrim(age,2) else $
printf, lun, 'Age = '

free_lun, lun

; Now read the file
openr, lun, 'test.input', /get_lun
buffer = ' '
while not eof(lun) do begin
readf, lun, buffer
parts = StrSplit(buffer, " ", /Extract)
case n_elements(parts) of
2: print, 'No value for ' + parts[0]
3: print, parts[0] + '= {' + parts[2] + '}'
else: print, 'Whoa, I am like totally confused!!'
endcase
endwhile
free_lun, lun
end

Then try it like this:

IDL> test, 'coyote', 'PE', 43
Name= {coyote}
Department= {PE}
Age= {43}

IDL> test
No value for Name
No value for Department
No value for Age

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: how get data from iSurface
Next Topic: Re: FSC_color and loadct clashing

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

Current Time: Fri Oct 10 12:30:18 PDT 2025

Total time taken to generate the page: 0.55948 seconds