Re: Simple text file reading question [message #56236] |
Wed, 10 October 2007 08:26 |
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  |
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  |
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
|
|
|