Commit 5d889fbf by dongshufeng

fix bug in read

parent c3b776c2
...@@ -57,7 +57,7 @@ pub fn read_terminal_cn_dev(records: &mut StringRecordsIter<&[u8]>) -> Result<Ve ...@@ -57,7 +57,7 @@ pub fn read_terminal_cn_dev(records: &mut StringRecordsIter<&[u8]>) -> Result<Ve
if let Ok(id) = str.parse() { if let Ok(id) = str.parse() {
terminals[row][col] = id; terminals[row][col] = id;
} else { } else {
return Err(format!("Wrong terminal input, row {row} col {col}")); return Err(format!("Wrong terminal input, row {row} col {col}: {str}"));
} }
col += 1; col += 1;
if col == 3 { if col == 3 {
...@@ -99,34 +99,31 @@ pub fn read_static_topo(records: &mut StringRecordsIter<&[u8]>, ...@@ -99,34 +99,31 @@ pub fn read_static_topo(records: &mut StringRecordsIter<&[u8]>,
if let Ok(id) = str.parse() { if let Ok(id) = str.parse() {
edges[row][col] = id; edges[row][col] = id;
} else { } else {
return Err(format!("Wrong static topology input, row {row} col {col}")); return Err(format!("Wrong static topology input, row {row} col {col}: {str}"));
} }
} else if col == 3 { } else if col == 3 {
if let Ok(type_u16) = str.parse::<u16>() { if let Ok(type_u16) = str.parse::<u16>() {
is_switch = type_u16 == swich_type; is_switch = type_u16 == swich_type;
if dev_type.is_some() {
dev_type.as_mut().unwrap().insert(edges[row][2], type_u16);
}
} else { } else {
return Err(format!("Wrong static topology input, row {row} col {col}")); return Err(format!("Wrong static topology input, row {row} col {col}: {str}"));
} }
} else if col == 4 && is_switch && normal_open.is_some() { } else if col == 4 && is_switch && normal_open.is_some() {
if let Ok(b) = str.parse::<bool>() { if let Ok(b) = str.parse::<bool>() {
normal_open.as_mut().unwrap().insert(edges[row][2], b); normal_open.as_mut().unwrap().insert(edges[row][2], b);
} else { } else {
return Err(format!("Wrong static topology input, row {row} col {col}")); return Err(format!("Wrong static topology input, row {row} col {col}: {str}"));
}
} else if col == 5 && is_switch && dev_type.is_some() {
if let Ok(v) = str.parse::<u16>() {
dev_type.as_mut().unwrap().insert(edges[row][2], v);
} else {
return Err(format!("Wrong static topology input, row {row} col {col}"));
} }
} }
col += 1; col += 1;
if col == 6 { if col == 5 {
break; break;
} }
} }
if col != 5 { if col != 5 {
return Err(format!("Wrong static topology input, expected col at least 6, actual {col}")); return Err(format!("Wrong static topology input, expected col at least 5, actual {col}"));
} }
} }
Some(Err(e)) => { Some(Err(e)) => {
......
...@@ -20,13 +20,13 @@ pub fn read_shunt_measures(records: &mut StringRecordsIter<&[u8]>) ...@@ -20,13 +20,13 @@ pub fn read_shunt_measures(records: &mut StringRecordsIter<&[u8]>)
if let Ok(id) = str.parse() { if let Ok(id) = str.parse() {
point = id; point = id;
} else { } else {
return Err(format!("Wrong terminal input, row {row} col {col}")); return Err(format!("Wrong shunt measure input, row {row} col {col}"));
} }
} else if col == 1 { } else if col == 1 {
if let Ok(id) = str.parse() { if let Ok(id) = str.parse() {
terminal = id; terminal = id;
} else { } else {
return Err(format!("Wrong terminal input, row {row} col {col}")); return Err(format!("Wrong shunt measure input, row {row} col {col}"));
} }
} else if col == 2 { } else if col == 2 {
meas.insert(point, (terminal, MeasPhase::from(str))); meas.insert(point, (terminal, MeasPhase::from(str)));
...@@ -37,11 +37,11 @@ pub fn read_shunt_measures(records: &mut StringRecordsIter<&[u8]>) ...@@ -37,11 +37,11 @@ pub fn read_shunt_measures(records: &mut StringRecordsIter<&[u8]>)
} }
} }
if col != 3 { if col != 3 {
return Err(format!("Wrong terminal input, expected col at least 3, actual {col}")); return Err(format!("Wrong shunt measure input, expected col at least 3, actual {col}"));
} }
} }
Some(Err(e)) => { Some(Err(e)) => {
return Err(format!("Wrong terminal input, err: {:?}", e)); return Err(format!("Wrong shunt measure input, err: {:?}", e));
} }
None => { None => {
break; break;
......
...@@ -38,7 +38,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -38,7 +38,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
if let Err(s) = &r2 { if let Err(s) = &r2 {
error = Some(s.clone()); error = Some(s.clone());
} else { } else {
let from = r2.unwrap(); let mut from = r2.unwrap();
for i in 0..input.dfs_len.len() { for i in 0..input.dfs_len.len() {
let size = input.dfs_len[i] as usize; let size = input.dfs_len[i] as usize;
let end = from + size; let end = from + size;
...@@ -81,6 +81,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -81,6 +81,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
Err(s) => error = Some(s), Err(s) => error = Some(s),
} }
} }
from += size;
} }
} }
if error.is_some() { if error.is_some() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论