[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reading file into structure?
- Subject: reading file into structure?
- From: Randall Skelton <rhskelto(at)atm.ox.ac.uk>
- Date: Wed, 18 Apr 2001 13:58:33 +0100
- Newsgroups: comp.lang.idl-pvwave
- Organization: Oxford University, England
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:24607
Hi all,
I am having a rather silly problem with reading in a simple ASCII file
directly into an IDL structure. Below is a simple procedure
'testread' and a sample ASCII file 'testfile'. NB: I've removed all the
error checking and striped down the procedure to limit its size...
What I want to do is read in data on line 20 directly into the data.values
but for some reason all I get are zeros in the 'values' array. If I read
the data directly into a float array, there is no problem? I am at a loss
here?
pro testread, file, data
sgas = '*TEST'
l = STRLEN(sgas)
OPENR, 1, file
header = '!'
nlev = 0
WHILE STRMID(header,0,1) EQ '!' DO READF, 1, header
READS, header, nlev
;data = fltarr(nlev) ;change comments if testing array
data = {basic_struct, comment: ' ', values: fltarr(nlev)}
WHILE STRMID(header,0,l) NE sgas DO BEGIN
READF, 1, header
IF STRLEN(header) LT l THEN header = header + ' '
header = STRUPCASE(header)
ENDWHILE
;READF, 1, data ;<-- this works.
READF, 1, data.values ;<-- why doesn't this work?
CLOSE, 1
END
-------------- testfile -------------
! Comments here
! Another line of comments
50
*blah [units]
0.0, 1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0, 9.0,
10.0, 11.0, 12.0, 13.0, 14.0,
15.0, 16.0, 17.0, 18.0, 19.0,
20.0, 21.0, 22.0, 23.0, 24.0,
25.0, 27.5, 30.0, 32.5, 35.0,
37.5, 40.0, 42.5, 45.0, 47.5,
50.0, 55.0, 60.0, 65.0, 70.0,
75.0, 80.0, 85.0, 90.0, 95.0,
100.0, 105.0, 110.0, 115.0, 120.0
*nextblah [units]
1.013E+03, 8.988E+02, 7.950E+02, 7.012E+02, 6.166E+02,
5.405E+02, 4.722E+02, 4.111E+02, 3.565E+02, 3.080E+02,
2.650E+02, 2.270E+02, 1.940E+02, 1.658E+02, 1.417E+02,
1.211E+02, 1.035E+02, 8.850E+01, 7.565E+01, 6.467E+01,
5.529E+01, 4.729E+01, 4.047E+01, 3.467E+01, 2.972E+01,
2.549E+01, 1.743E+01, 1.197E+01, 8.010E+00, 5.746E+00,
4.150E+00, 2.871E+00, 2.060E+00, 1.491E+00, 1.090E+00,
7.978E-01, 4.250E-01, 2.190E-01, 1.090E-01, 5.220E-02,
2.400E-02, 1.050E-02, 4.460E-03, 1.840E-03, 7.600E-04,
3.200E-04, 1.450E-04, 7.100E-05, 4.010E-05, 2.540E-05
*TEST [md]
288.20, 281.70, 275.20, 268.70, 262.20,
255.70, 249.20, 242.70, 236.20, 229.70,
223.30, 216.80, 216.70, 216.70, 216.70,
216.70, 216.70, 216.70, 216.70, 216.70,
216.70, 217.60, 218.60, 219.60, 220.60,
221.60, 224.00, 226.50, 230.00, 236.50,
242.90, 250.40, 257.30, 264.20, 270.60,
270.70, 260.80, 247.00, 233.30, 219.60,
208.40, 198.60, 188.90, 186.90, 188.40,
195.10, 208.80, 240.00, 300.00, 360.00
*lastblah [units]
7.745E+03, 6.071E+03, 4.631E+03, 3.182E+03, 2.158E+03,
1.397E+03, 9.254E+02, 5.720E+02, 3.667E+02, 1.583E+02,
6.996E+01, 3.613E+01, 1.906E+01, 1.085E+01, 5.927E+00,
5.000E+00, 3.950E+00, 3.850E+00, 3.825E+00, 3.850E+00,
3.900E+00, 3.975E+00, 4.065E+00, 4.200E+00, 4.300E+00,
4.425E+00, 4.575E+00, 4.725E+00, 4.825E+00, 4.900E+00,
4.950E+00, 5.025E+00, 5.150E+00, 5.225E+00, 5.250E+00,
5.225E+00, 5.100E+00, 4.750E+00, 4.200E+00, 3.500E+00,
2.825E+00, 2.050E+00, 1.330E+00, 8.500E-01, 5.400E-01,
4.000E-01, 3.400E-01, 2.800E-01, 2.400E-01, 2.000E-01
-------------- EOF -------------