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

Home » Public Forums » archive » Read ASCII
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Read ASCII [message #10593 is a reply to message #10591] Wed, 07 January 1998 00:00 Go to previous messageGo to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
David Mottershead (DMottershead@mhl.nsw.gov.au) writes
from down under:

> I am trying to read in some ASCII data in a column form with a format
> defined in my main procedure like this:
>
> fileData = {WBD_File, $
> yr:0, $
> mn:0, $
> day:0, $
> hour:0, $
> minute:0, $
> value:0.0}

[much code clipped]

I've read this post over quite a few times, and I am still
not *totally* sure I understand what you are trying to do.
It looks to me like you have column data in the form of
6 columns by 35136 rows. Going on that assumption, I would
say you are trying to do too much all at once. Take it a
little bit slower.

I might try it like this. I would make my info structure,
which is where I store *all* of the information I need to
make my program work, with a field for the data template
and another field for the data itself. It might be defined
like this:

fileData = {WBD_File, yr:0, mn:0, day:0, hour:0, $
minute:0, value:0.0}
info = { template:fileData, $ ; The file template.
header:StrArr(5), $ ; Five line data file header.
rows:35136L, $ ; Number of rows in the data files.
data:Ptr_New() } ; A null pointer, for now.

And just from this one code example, I'm guessing this program
could use a little modularity. I would probably define the
Open File button like this, so I could work with a smaller
event handler:

openfileID = Widget_Button(menubase, Value='Open File...', $
Event_Pro='Open_File_Button_Event')

So, then, my event handler might look something like this:

PRO Open_File_Button_Event, event

; Get the data file name from the user.

filename = Dialog_Pickfile(/Read, Filter='*.dat')
IF filename EQ '' THEN RETURN

; Go read the file. First, get the info structure.

Widget_Control, event.top, Get_UValue=info, /No_Copy

; Create an array of structures. Read the data.

dataArray = Replicate(info.template, info.rows)
OpenR, lun, filename, /Get_Lun
Readf, lun, info.header, dataArray
Free_Lun, lun

; Make the data vectors.

yr = dataArray(*).(0)
mn = dataArray(*).(1)
day = dataArray(*).(2)
hour = dataArray(*).(3)
minute = dataArray(*).(4)
value = dataArray(*).(5)

; Store data as structure in the pointer location.

info.data = Ptr_New({yr:yr, mn:mn, day:day, hour:hour, $
minute:minute, value:value}, /No_Copy)

Widget_Control, event.top, Set_UValue=info, /No_Copy
END

Now, any module that needs to do something with the data
can access it like this:

Plot, (*info.data).day, (*info.data).value

Hope that gives you some ideas.

Cheers,

David

P.S. You might also look at the two new functions ASCII_TEMPLATE
and READ_ASCII. They are made specifically to read this kind
of column data.

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: idl for solaris
Next Topic: IDL and sqlite

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

Current Time: Wed Oct 08 18:35:18 PDT 2025

Total time taken to generate the page: 0.00443 seconds