Moving array of data into a table [message #6604] |
Thu, 25 July 1996 00:00 |
JH7
Messages: 2 Registered: July 1996
|
Junior Member |
|
|
I need to be able to convert an array of structures to a table so that
I can do a query on it.
The build_table function can not do this since it does not accept
variables that are a part of a structure it only accepts 1D vectors of
data.
Ex. This code shows that a data file of unknown structure has been
read into an array of structures. Which should then be transfered
into a table.
; Code to read the data file and put the data into a stucture
nfields = 50 ; this value is read from ascii file header
nrec = 20 ; this is calculated from file length
; The names of the fields in the record are given in the header as
; well the structure of the each record
; It looks like the following
data_rec = {struct, time:0.0, frame:0L, var:fltarr(nfields-2)}
d =assoc(unit,struct,offset) ;use assoc to read records from the file
data = replicate(struct,nrec) ; create an arrary of records
for i=0,nrec-1 do begin ; read each record from file
data(i) = d(i) ; into the arrary structure
endfor
; Code to tranfer data from structure to the table
; Create a string to be used by build_table to relate the data in the
; data structure to the columns of data in the table. This string is
; actually generated from a description header that describes the file
; format. One would assume data.time, data.frame, etc... would be a
; 1-D array but pv-wave does not see it that way
table_str = 'data.time TIME, data.frame FRAME, &
data.var(0) POSX, data.var(1) POSY, ..., &
data.var(49) SIZE'
; I get an error on the next line because data.time is not
; considered to be a pv-wave variable
table = build_table(table_str)
Or even better... is there a better way to read a file as shown
above directly or indirectly into a table and have the names assigned
to each column of data appropriately? However, the structure of the
file(table) is unknown until the description header has been read.
John Houston
houston@ti.com
|
|
|