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

Home » Public Forums » archive » Re: Simple text file reading question
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
Re: Simple text file reading question [message #56236] Wed, 10 October 2007 08:26
rpertaub@gmail.com is currently offline  rpertaub@gmail.com
Messages: 43
Registered: January 2007
Member
On Oct 10, 11:08 am, Brian Larsen <balar...@gmail.com> wrote:
> I am assuming you have tried this and got this error:
> % READF: Input conversion error. Unit: 101, File: data.txt
> % Execution halted at: $MAIN$
>
> the issue is that you have to initialize read variables to strings if
> you want to read strings.
>
> this is the code I used:
> IDL> openr, lun, 'data.txt', /get_lun
> IDL> readf, lun, in1
> IDL> readf, lun, in2
> IDL> readf, lun, in3
> IDL> in4 = ''
> IDL> readf, lun, in4
> IDL> help, in1, in2, in3, in4
> IN1 FLOAT = 650.000
> IN2 FLOAT = 550.000
> IN3 FLOAT = 480.000
> IN4 STRING = 'chimeny.sav '
>
> Cheers,
>
> Brian
>
> ------------------------------------------------------------ ---------------------
> Brian Larsen
> Boston University
> Center for Space Physics

Thank so much for your help!! It works...my whole program
works...hopefully I won't have to write another one for a while...
Re: Simple text file reading question [message #56237 is a reply to message #56236] Wed, 10 October 2007 08:08 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
I am assuming you have tried this and got this error:
% READF: Input conversion error. Unit: 101, File: data.txt
% Execution halted at: $MAIN$

the issue is that you have to initialize read variables to strings if
you want to read strings.


this is the code I used:
IDL> openr, lun, 'data.txt', /get_lun
IDL> readf, lun, in1
IDL> readf, lun, in2
IDL> readf, lun, in3
IDL> in4 = ''
IDL> readf, lun, in4
IDL> help, in1, in2, in3, in4
IN1 FLOAT = 650.000
IN2 FLOAT = 550.000
IN3 FLOAT = 480.000
IN4 STRING = 'chimeny.sav '




Cheers,

Brian

------------------------------------------------------------ ---------------------
Brian Larsen
Boston University
Center for Space Physics
Re: Simple text file reading question [message #56238 is a reply to message #56237] Wed, 10 October 2007 08:04 Go to previous message
enod is currently offline  enod
Messages: 41
Registered: November 2004
Member
On Oct 10, 10:25 pm, "rpert...@gmail.com" <rpert...@gmail.com> wrote:
> Hi,
> I need to read a text file and assign the strings (and numbers) I read
> to variables.
> My text file contains:
>
> data.txt
> 650
> 550
> 480
> chimeny.sav
>
> I need to assign the first 3 numbers to 3 variables and the string to
> another variable.
>
> Any help?
>
> Thanks,
> RP

Just open it and read line by line.

PRO data_read
OPENR, lun, 'data.txt', /GET_LUN
tmp=''
readf, lun, tmp
int1 = fix(tmp)
readf, lun, tmp
int2 = fix(tmp)
readf, lun, tmp
int3 = fix(tmp)
readf, lun, tmp
str = tmp
FREE_LUN, lun
END


Regards,
Tian
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 3D registration
Next Topic: Minor IDL code changes cause large slowdowns elsewhere in code

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

Current Time: Wed Oct 08 18:07:03 PDT 2025

Total time taken to generate the page: 0.00578 seconds