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

Home » Public Forums » archive » Re: need help with ascii I/O second try. Ignor first!!
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: need help with ascii I/O second try. Ignor first!! [message #18521] Tue, 04 January 2000 00:00
peter brooker[1] is currently offline  peter brooker[1]
Messages: 5
Registered: January 2000
Junior Member
thanks Liam. This is exactly what I needed.

Peter Brooker


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
Re: need help with ascii I/O second try. Ignor first!! [message #18522 is a reply to message #18521] Tue, 04 January 2000 00:00 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
peter brooker wrote:
> One of our measurement tools generate an ascii output file
> that looks like the following.
>
> DEVICE LAYER SLOT DATE TIME SITE MEAS
> x19y n53 B2 8/24/99 8:28:48 PM 1 0.5663
> x19y n53 B2 8/24/99 8:29:20 PM 2 0.5692
> x19y n53 B2 8/24/99 8:30:01 PM 3 0.5762
> x19y n53 B2 8/24/99 8:32:43 PM 4 0.5666
>
> The data I care about for each group are in the last two
> columns. I do not care about the first line. The spacing
> between the columns varies.
>
> What is the best way to read in the lines and then store
> the information from the last two columns into real arrays?

Try this:

;---cut here---
PRO TEST, DATA

;- Open the file
openr, lun, 'test.dat', /get_lun

;- Skip the first line
blank = ''
readf, lun, blank, format='(a1)'

;- Read all records
data = fltarr(2, 100000)
nrec = 0
while not eof(lun) do begin

;- Read current record
record = ''
readf, lun, record

;- Separate the string into columns
record = strcompress(record)
record = str_sep(record, ' ')

;- Get the last two columns
ncols = n_elements(record)
var1 = record[ncols - 2]
var2 = record[ncols - 1]

;- Store in data array
data[0, nrec] = float(var1)
data[1, nrec] = float(var2)

;- Increment record counter
nrec = nrec + 1

endwhile

;- Close the file
free_lun, lun

;- Trim data array
data = data[*, 0:nrec-1]

END
;---cut here---

Assuming your data file is named test.dat:

IDL> .compile test
% Compiled module: TEST.
IDL> test, data
% Compiled module: STR_SEP.
IDL> help, data
DATA FLOAT = Array[2, 4]
IDL> print, data
1.00000 0.566300
2.00000 0.569200
3.00000 0.576200
4.00000 0.566600

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Windows DLMs
Next Topic: Need help with ascii I/O 3rd try. Ignor 1 & 2

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

Current Time: Wed Oct 08 17:02:44 PDT 2025

Total time taken to generate the page: 0.00642 seconds