Skip to content

Commit

Permalink
Fix counting of rows
Browse files Browse the repository at this point in the history
- since data for each Transformer is spread over
  multiple lines, we can now have a line start with '0'
  and it not indicate the end of the section (since
  it in the middle of the data for a Transformer, not
  the start of a new record).
  • Loading branch information
nickrobinson251 committed Sep 29, 2021
1 parent 4608a92 commit d1a5b47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ function count_nrow(buf, pos, len, options)
pos += res.tlen
if newline(res.code) || eof(res.code)
nlines += 1
if eof(buf, pos, len) || peekbyte(buf, pos) == UInt8('0')
if eof(buf, pos, len) || (
!eof(buf, pos, len) && peekbyte(buf, pos) == UInt8('0') &&
!eof(buf, pos+1, len) && peekbyte(buf, pos+1) == UInt8(' ')
)
break
end
end
Expand Down
21 changes: 12 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ using Test
@test branches.ckt[2] == "6 "

transformers = net2.two_winding_transformers
@test transformers.i == [42, 4774] # 1st entry of 1st row
@test transformers.fi == [1.0, 1.0] # last entry of 1st row
@test transformers.r1_2 == [0.0025, 0.0] # 1st entry of 2nd row
@test transformers.sbase1_2 == [100.0, 100.0] # last entry of 2nd row
@test transformers.windv1 == [1.0, 1.0462] # 1st entry of 3rd row
@test transformers.cx1 == [0.0, 0.0] # last entry of 3rd row
@test transformers.windv2 == [1.0, 1.045] # 1st entry of 4th row
@test transformers.nomv2 == [138.0, 240.35] # last entry of 4th row
@test transformers.ckt == ["K1", "90"] # string col
@test length(transformers.i) == 3
@test transformers.i == [42, 4774, 222222] # 1st entry of 1st row
@test transformers.fi == [1.0, 1.0, 1.0] # last entry of 1st row
@test transformers.r1_2 == [0.0025, 0.0, 0.0005] # 1st entry of 2nd row
@test transformers.sbase1_2 == [100.0, 100.0, 100.0] # last entry of 2nd row
@test transformers.windv1 == [1.0, 1.0462, 1.0] # 1st entry of 3rd row
@test transformers.cx1 == [0.0, 0.0, 0.0] # last entry of 3rd row
# Important to test a row where the 1st character is '0', to get it does not
# get misinterpreted as the start of a "0 bus" records terminating the section.
@test transformers.windv2 == [1.0, 1.045, 0.98250] # 1st entry of 4th row
@test transformers.nomv2 == [138.0, 240.35, 345.0] # last entry of 4th row
@test transformers.ckt == ["K1", "90", "B1"] # string col
end
end
4 changes: 4 additions & 0 deletions test/testfiles/synthetic_data_v29.raw
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
0.00000, 0.19100, 100.00
1.04620, 13.600, 0.000, 0.00, 0.00, 0.00, 0, 0, 1.04620, 1.04620, 0.00000, 0.00000, 2, 0, 0.00000, 0.00000
1.04500, 240.350
222222, 11, 0,'B1',1,1,1, 0.00000, 0.00000,2,' BK1 ',1, 2,1.0000
0.00050, 0.03131, 100.00
1.00000, 123.000, 0.000, 432.00, 567.00, 567.00, 0, 0, 1.00000, 1.00000, 0.00000, 0.00000, 2, 0, 0.00000, 0.00000
0.98250, 345.000
0 / END OF TRANSFORMER DATA, BEGIN AREA DATA
0 / END OF AREA DATA, BEGIN TWO-TERMINAL DC DATA
0 / END OF TWO-TERMINAL DC DATA, BEGIN VSC DC LINE DATA
Expand Down

0 comments on commit d1a5b47

Please sign in to comment.