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

Home » Public Forums » archive » Re: Help needed with reading ASCII data
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: Help needed with reading ASCII data [message #18131] Fri, 03 December 1999 00:00
Michael Asten is currently offline  Michael Asten
Messages: 53
Registered: March 1999
Member
Liam Gumley wrote:I'm assuming your data file looks something like this:

>
> 0, 0, 0.998
> 1, 0, 0.976
> 2, 0, 0.876
>
> It sounds like you're not really interested in the x and y coordinates,
> since they are probably the same for all 22 time phases. In this case,
> you can read the array in one hit:
>
> ;- Read the data file
> openr, lun, 'mri.dat', /get_lun
> data = fltarr(3, 38808)
> readf, lun, data
> free_lun, lun
>
> ;- Extract the magnitude array
> h = data[2, *]
> h = reform(h, 49, 36, 22)
>
> ;- Visualize the data as an image sequence
> mag = 5
> for index = 0, 21 do tvscl, rebin(h[*, *, index], mag*49, mag*36, 1,
> /sample)
>
> Cheers,
> Liam.
>

Or, if your data file is not always of identical length, try using the idl
routine READ_ASCII, which will read an arbitrary number of columns and rows
of any data type, into a structure.

Regards,
Michael Asten
Re: Help needed with reading ASCII data [message #18132 is a reply to message #18131] Fri, 03 December 1999 00:00 Go to previous message
John Keck is currently offline  John Keck
Messages: 10
Registered: August 1996
Junior Member
> I'm completely new to IDL, and I have a set of data in ASCII format. It
> is extracted from MRI data. It is a file which contains 3 columns of
> data. The first column is the x, the second is the y coordinate and the
> third is just a scaled magnitude value between 0 and 1. There are 38808
> rows of data, and the matrix size is (49, 36) and there are 22 time
> phases. I want to know if anyone has had experience in reading in data
> of this type, and how to put it into an array that can be read by IDL.

Dear Scott,

The easier thing to do (programming-wise) is to use the READCOL
procedure, which I believe is part of one of the standard libraries that
you can download (you can search these libraries from
http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.h tml)

Your data file is a bit big though, so that may take quite a while.
I've found a much faster way to read in big files is to set up a
structure and a print-type format to read in the data. Something like
this:

filename = "foo.dat"
fmt = "(i3,3F7.2)" ; of course this has to match the format of your
columns

cog = {det $
,t: 0 $
,x: 0. $
,y: 0. $
,z: 0.)

all = REPLICATE(cog,nl) ; NL = # lines in file

OPENR,lun,/GET_LUN,filename
READF,lun, FORMAT=fmt,all
FREE_LUN,lun
END

Anyway, that should read in your file at one blow. You can then
re-arrange the data in your arrays as you like. (You may want to look
up the IDL help files on structures; it might be helpful to know that
you can address the fields of a structure with numbers and can to a
large extent treat a structure as an array.)

I hope that's helpful.

Sincerely,

John Keck
Re: Help needed with reading ASCII data [message #18139 is a reply to message #18131] Fri, 03 December 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Scott Reid wrote:
> I'm completely new to IDL, and I have a set of data in ASCII format. It
> is extracted from MRI data. It is a file which contains 3 columns of
> data. The first column is the x, the second is the y coordinate and the
> third is just a scaled magnitude value between 0 and 1. There are 38808
> rows of data, and the matrix size is (49, 36) and there are 22 time
> phases. I want to know if anyone has had experience in reading in data
> of this type, and how to put it into an array that can be read by IDL.
> I know how to open the data and display it, with the following
>
> openr, 1, filepath(..)
> :
> : HELP WITH THE READING OF THE ACII DATA PLEASE!!!!!!
> :
> :
> h=fltarr(49,36,22)
> close, 1
> loadct, 3
> h = rebin(h, 32, 32, 22)
> frames = fltarr(256, 256, 22)
> window, 1, TITLE='Bloodflow animation', xsize=256, ysize=256
> for i=0, 22 do begin surface, h[*, *, i], zrange=[0, 1] & frames[0,0,i]
> = tvrd() & end
>
> If anyone could help me with reading the ASCII data and putting it into
> an array which IDL can read, I would be most grateful

I'm assuming your data file looks something like this:

0, 0, 0.998
1, 0, 0.976
2, 0, 0.876

It sounds like you're not really interested in the x and y coordinates,
since they are probably the same for all 22 time phases. In this case,
you can read the array in one hit:

;- Read the data file
openr, lun, 'mri.dat', /get_lun
data = fltarr(3, 38808)
readf, lun, data
free_lun, lun

;- Extract the magnitude array
h = data[2, *]
h = reform(h, 49, 36, 22)

;- Visualize the data as an image sequence
mag = 5
for index = 0, 21 do tvscl, rebin(h[*, *, index], mag*49, mag*36, 1,
/sample)

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: Help needed with reading ASCII data [message #18140 is a reply to message #18131] Fri, 03 December 1999 00:00 Go to previous message
Bernard Puc is currently offline  Bernard Puc
Messages: 65
Registered: January 1998
Member
Scott Reid wrote:
>
> Hi All
>
> I'm completely new to IDL, and I have a set of data in ASCII format. It
> is extracted from MRI data. It is a file which contains 3 columns of
> data. The first column is the x, the second is the y coordinate and the
> third is just a scaled magnitude value between 0 and 1. There are 38808
> rows of data, and the matrix size is (49, 36) and there are 22 time
> phases. I want to know if anyone has had experience in reading in data
> of this type, and how to put it into an array that can be read by IDL.

I typically do something like this when reading delimited ASCII data.
Each line is read into a string and then the string is divided into an
array of strings. Then you do what you will with the values in the
array:

OPENR,Lun,/Get_Lun,Filename
sString = ''
WHILE NOT(EOF(Lun)) DO BEGIN
READF,Lun,sString
tempArray = str_sep(sString, string(byte(32))) ;Replace with ASCII code
of delimiter
index = WHERE( tempArray NE '', num)
IF num GT 0 THEN tempArray = tempArray[index]

x = float(tempArray[0])
y = float(tempArray[1])
s = float(tempArray[2])
;You would assign these values to fill your array: fltarr(49,36,22)

END

--
Bernard Puc AETC, INC.
bpuc@va.aetc.com 1225 Jefferson Davis Highway #800
(703) 413-0500 Arlington, VA 22202
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: do I really need to use loops on objects?
Next Topic: POLYFILLV for 3D to create volumes

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

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

Total time taken to generate the page: 0.00470 seconds