How to read file to fill an array "partially" ? [message #56187] |
Tue, 16 October 2007 14:19  |
mystea
Messages: 16 Registered: October 2007
|
Junior Member |
|
|
Hello All,
I am trying to read data from an ASCII file. The format of the file is
as follows.
"mydata.txt":
5
7.7
8.1
9.0
1.1
3.0
3
2.2
1.0
2.2
Namely, the first line tells you how many entries are there, and the
data follows. I plan to save them in a 2*5 array "myarray." So the
following is what I am doing:
openr, lun, 'mydata.txt', /get_lun ;open file
myarray=dblarr(2,5) ;declare array to
store data
n_entries=0S ;declare variable
to store number of entries
for i=0, 1 do begin ;try to fill
"myarray" by a for loop
readf, lun, n_entries ;read in # of
entries
n_entries=fix(n_entries-1S) ;the final index of
valid entry is # of entries minus one.
readf, lun, myarray[i,0:n_entries] ;read data into
myarray[i,0:# of entries -1]
endfor
However, it does not work! All I get is 0.00000 for all the entries I
have. (data does not seem to be read)
I tried to use format code, it doesn't help either. However, the
terminal replies:
% Attempt to store into an expression: <DOUBLE Array[5]>.
so I guess IDL does not allow data to be read to stuff like
myarray[0,0:4] because it is an "expression" instead of a real array.
I have three simple questions:
1. How to read data and stored partially to an array?
2. Why the response "% Attempt to store into an expression" does not
show up when I wasn't offering formats?
3. (might be the answer to the first question) How can I find the
reference address of a certain portion of an array?
P.S.Of course my data is much larger, I modified them to 2*5 in order
to make the case clearer.
|
|
|