07-17-2013 01:40 AM
Hello
I try to import particel counter data from a text file which is organized in a difficult way:
Data come in blocks with each block taken at one time. Each block consists of a table of tab-separated data. e.g.
(start of Block 1)
04.06.2013 - 16:34:13 - 10s/10 - m
N analysed: 1521 P Sum(dCn): 5444,470 P/cm³
N total: 1521 P Sum(dCm): 1,7536 mg/m³
X [µm] 0,148647 0,159737 0,171655 0,184462 0,198224 0,213013 0,228905 0,245984 0,264336 0,284057
dN [P] 0 0 0 6.155.882 29.521.097 101.420.330 83.226.951 85.545.715 159.120.955 158.057.455
dN/N [-] 0 0 0 0,004048 0,019414 0,066696 0,054732 0,056256 0,104641 0,103941
dN/N/dX [1/µm] 0 0 0 0,305126 1.361.669 4.353.255 3.324.322 3.179.709 5.503.848 5.087.496
dCn [P/cm³] 0 0 0 22.040.393 105.696.730 363.123.274 297.984.071 306.286.127 569.713.408 565.905.674
dCn/Cn [-] 0 0 0 0,004048 0,019414 0,066696 0,054732 0,056256 0,104641 0,103941
dCn/Cn/dX [1/µm] 0 0 0 0,305126 1.361.669 4.353.255 3.324.322 3.179.709 5.503.848 5.087.496
(start of Block 2)
04.06.2013 - 16:34:23 - 10s/10 - m
N analysed: 1071 P Sum(dCn): 3833,350 P/cm³
N total: 1071 P Sum(dCm): 0,3581 mg/m³
X [µm] 0,148647 0,159737 0,171655 0,184462 0,198224 0,213013 0,228905 0,245984 0,264336 0,284057
dN [P] 0 0 0 6.981.271 18.451.972 25.599.194 70.809.673 88.966.677 122.491.615 83.363.748
dN/N [-] 0 0 0 0,006521 0,017234 0,02391 0,066137 0,083096 0,114408 0,077862
dN/N/dX [1/µm] 0 0 0 0,491474 1.208.812 1.560.603 4.017.064 4.696.707 6.017.589 3.811.039
dCn [P/cm³] 0 0 0 24.995.600 66.065.063 91.654.830 253.525.502 318.534.467 438.566.469 298.473.857
dCn/Cn [-] 0 0 0 0,006521 0,017234 0,02391 0,066137 0,083096 0,114408 0,077862
dCn/Cn/dX [1/µm] 0 0 0 0,491474 1.208.812 1.560.603 4.017.064 4.696.707 6.017.589 3.811.039
(start of Block 3)
04.06.2013 - 16:34:33 - 9s/9 - m
N analysed: 1277 P Sum(dCn): 5080,103 P/cm³
N total: 1277 P Sum(dCm): 2,2456 mg/m³
X [µm] 0,148647 0,159737 0,171655 0,184462 0,198224 0,213013 0,228905 0,245984 0,264336 0,284057
dN [P] 0 0 6.983.139 13.137.502 30.294.664 52.503.076 114.177.807 82.937.875 112.476.377 117.880.295
dN/N [-] 0 0 0,005468 0,010288 0,023724 0,041115 0,089412 0,064948 0,08808 0,092311
dN/N/dX [1/µm] 0 0 0,442925 0,77543 1.663.971 2.683.579 5.430.769 3.670.984 4.632.772 4.518.256
dCn [P/cm³] 0 0 27.780.321 52.263.604 120.518.214 208.867.707 454.222.092 329.943.409 447.453.461 468.951.325
dCn/Cn [-] 0 0 0,005468 0,010288 0,023724 0,041115 0,089412 0,064948 0,08808 0,092311
dCn/Cn/dX [1/µm] 0 0 0,442925 0,77543 1.663.971 2.683.579 5.430.769 3.670.984 4.632.772 4.518.256
(This is of course only an excerpt. There may be more blocks and there will be more size channels and more channel groups...)
Now, I want to store the dN values in one channel group, the dN/N in the next group etc. There should be 10 channels, one for each size class, and the data from the various blocks as sequential values in these channels. (I hope I wa able to explain this in a comprehensoble way...)
I can generate the groups and the respective channels:
'****************************************************************
set oChn = ochngrp.Channels(2) 'Der Kanal mit den mittleren Dm wird für die Kanalnamen der Gruppen weiterverwendet
for i = 1 to 25
sMyLine = file.getnextline
aChnData = split(sMyLine,vbTab,-1,vbTextCompare) 'Read one line and parse it into an array
if not Root.ChannelGroups.Exists(aChnData(0)) then 'test if a group named like array(0) exists
Set oChnGrp = Root.ChannelGroups.Add(aChnData(0)) ' and create one if necessary.
for j = 1 to oChn.Size
call oChnGrp.Channels.Add("" & oChn(j),eR64) 'add empty channels
next
end if
next
'****************************************************************
How would I read the data?
With a lot of nested i,j-for..next loops, I could read a line via
for j = 1 to root.channelgroups.count
aValue = split(file.getnextline)
for i = 1 to 10
root.channelgroups(j).values(i) = aValue(i)
next
next
' then jump to timestamp of next data block with some skiplines, read timestamp and reiterate
or I could try to read all values for one channel group and use skiplines, e.g.
for i = 1 to root.channelgroups.count
while file.position <> file.size
aValue(j) = split(file.getnextline)
file.skiplines(as many as are between the blocks)
wend
' now I have a 2dim array aValue to transfer into data channels.But how?
file.position = 1
next
Could file.GetStringBlock be of any help?
Has anybody tackled a similar file structure and could give me a clue or some code sniplet?
Thank you...
Michael
07-19-2013 11:42 AM
Hi Michael,
I would just go line by line in the data file and send the array channel values (one value at a time) to the Channel.Values() property of the matching channel name. It's not going to be fast any way you do it in VBScript.
Brad Turpin
DIAdem Product Support Engineer
National Instruments