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

Home » Public Forums » archive » reading data with numbers and strings from data file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
reading data with numbers and strings from data file [message #89649] Thu, 06 November 2014 02:40 Go to next message
abc is currently offline  abc
Messages: 46
Registered: March 2011
Member
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
Re: reading data with numbers and strings from data file [message #89650 is a reply to message #89649] Thu, 06 November 2014 05:19 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
this should do it

openr,1,filename

s=""
read,1,s
read,1,s
read,1,s

a1=dblarr(14) ;I'm guessing all your arrays have 14 elements, and that other stuff is from your 3rd line

read,1,a1
read,1,s

b1=dblarr(14)
read,1,b1
read,1,s

c1=dblarr(14)
read,1,c1
read,1,s

close,1

cheers,
Greg
Re: reading data with numbers and strings from data file [message #89651 is a reply to message #89649] Thu, 06 November 2014 06:04 Go to previous messageGo to next message
abc is currently offline  abc
Messages: 46
Registered: March 2011
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

Thanks Greg, for your help. But the data which I posted is just a example. My file is very huge and I am having more then 14 elements. Though I tried the way you wrote but it didn't work :-( .
Re: reading data with numbers and strings from data file [message #89652 is a reply to message #89651] Thu, 06 November 2014 07:14 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
You probably need to explain where it went wrong. It doesn't help that we can't see where the line wraps occur in your post.

Greg
Re: reading data with numbers and strings from data file [message #89653 is a reply to message #89649] Thu, 06 November 2014 07:52 Go to previous message
lecacheux.alain is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: strange postscript error on certain IDL plots
Next Topic: Coord_transform in axes

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

Current Time: Wed Oct 08 09:13:05 PDT 2025

Total time taken to generate the page: 0.00410 seconds