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

Home » Public Forums » archive » Re: Reading data, from a file
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: Reading data, from a file [message #79930] Fri, 13 April 2012 04:35
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Friday, 13 April 2012 13:05:59 UTC+2, shambhu wrote:
> Hi,
>
> Please check the following code. I want to print the data from the
> first line, but when i assign t=dummy(0) it taking 5th value from the
> dummy. So please help me on this.
>
> dummy = strarr(5)
>
> openr,lun,'cdays.dat.old',/get_lun
>
> for j=0, 2 do begin
> readf,lun,dummy
> ;readf, lun ,dummy(0)
> t=dummy(0) & print,'T val is', t
> print,dummy
> endfor
>
> free_lun,lun

This code is not doing what you think it does. "readf, lun, dummy" will read 5 lines from the data file. Thus, "dummy[0]" will contain the first of these.

You want something like this:

file = 'cdays.dat.old'
nLines = file_lines(file)

data = strarr(nLines)
openr, lun, file, /get_lun
readf, lun, data
free_lun, lun

data = (strsplit(data, /extract)).toarray() ; Requires IDL 8 (loop over lines in IDL 7)
data = double(data)

--
Yngvar
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Reading data, from a file
Next Topic: Interfacing IDL and COM objects

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

Current Time: Wed Oct 08 15:27:46 PDT 2025

Total time taken to generate the page: 0.00591 seconds