Re: reading data with numbers and strings from data file [message #89653 is a reply to message #89649] |
Thu, 06 November 2014 07:52  |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On Thursday, November 6, 2014 11:40:54 AM UTC+1, deear...@gmail.com wrote:
> Dear All,
> I am having little trouble in reading some ASCII files. The data I am having in my ASCII files is as follows:
>
> saved results 20
> 128 37
> 1.5000D+02 1.0168D+10 0.0000D+00 1.0000D-03 0 4 4 0.0000D+00 1.0168D+10
> 0.00000000000000000D+00 1.00000000000000006D-09 1.76210484793750211D-09
> 3.10501349512486019D-09 5.47135933267088403D-09 9.64110880490750049D-09
> 1.69886445646204793D-08 2.99357729472049009D-08 5.27499706370261988D-08
> 9.29509789880649348D-08 1.63789370695406457D-07 2.88614044143008960D-07
> 5.08568206367245386D-07 8.96150501946604958D-07 2.23094262494154714D-06
> 4.30065583610536799D-06 6.73281626852004125D-06
> A1 0 0
> 3.03178442790896588D+03 3.03178442790896588D+03 3.03814926483268664D+03
> 3.03955417139188103D+03 3.03822673621599688D+03 3.03985650457928796D+03
> 3.04657676876905316D+03 3.05405168962787593D+03 3.05040386156178738D+03
> 3.01543371816092713D+03 2.97921155702434407D+03 2.97680212751912359D+03
> 2.99000791149612724D+03 3.00042444894014034D+03
> B1 0 0
> 3.03178442790896588D+03 3.03178442790896588D+03 3.03814926483268664D+03
> 3.03955417139188103D+03 3.03822673621599688D+03 3.03985650457928796D+03
> 3.04657676876905316D+03 3.05405168962787593D+03 3.05040386156178738D+03
> 3.01543371816092713D+03 2.97921155702434407D+03 2.97680212751912359D+03
> 2.99000791149612724D+03 3.00042444894014034D+03
> C1 0 0
> a b c d e f
> a b c d e f
> a b c d e f
> a b c d e f
> a b c d e f
> a b c d e f
>
>
>
> I want to skip first 3 rows and then want to read the data in way that it will store all data corresponding to A1 in array in A1. Similarly data corresponding to B1 in array in B1 and so on. I want to skip all the data after C1. If some one know how to do that in IDL then it will be really appreciable.
>
> Thanks in advance
If the "format" of your file is not simple, I would first read your entire file to a string array. Then tranfer ascii encoded data to binary array as needed.
For instance:
n = file_lines(filename)
s = strarr(n)
openr, lun, /GET_LUN, filename
readf, lun, s
free_lun, lun
w1 = where(strpos(s, 'A1') ge 0) ;search number of lines containing 'A1' and 'B1'
w2 = where(strpos(s, 'B1') ge 0) ;you can adapt those tests as needed
;extracting relevant lines
ss = strsplit(s[w1+1:w2-1], ' ', COUNT=nn, /EXTRACT)
;cretaing binary data
a1 = dblarr(nn)
reads, ss, a1
etc...
alx.
|
|
|