From 8f37deb27bb959c593ee4a69ace1a52fa6331f9d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 16 Jan 2013 15:33:10 +0100 Subject: scripts/csv2sto.py: Fix bugs regarding # of rows/columns in .sto We wrote to few columns when combining multiple CSV files and were always wrongly counting the header row as a data row for nRows in the .sto file. --- scripts/csv2sto.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/csv2sto.py b/scripts/csv2sto.py index be8438e..4275fb1 100755 --- a/scripts/csv2sto.py +++ b/scripts/csv2sto.py @@ -72,28 +72,32 @@ def main(): sys.exit(-1) # determine number of columns and rows - tot_nRows = tot_nCols = 0 + tot_nRows = 0 + tot_nCols = 1 # initial time column (as we omit it when taking data from each CSV) for f_csv in fs_csv: fd = open(f_csv, 'r') - nRows = nColumns = 0 + + nRows = nCols = 0 for line in fd: if nRows == 0: nCols = len(line.split(',')) nRows += 1 + if tot_nRows == 0: tot_nRows = nRows elif tot_nRows != nRows: print("Error: Number of rows in CSV files do not match") sys.exit(-1) - if tot_nCols == 0: - tot_nCols = nCols - elif tot_nCols != nCols: - print("Error: Number of columns in CSV files do not match") - sys.exit(-1) + + # add up to the total number of colums but omit time column + tot_nCols += nCols - 1 fd.close() - print("Writing sto file {} with name {}".format(f_sto, name)) + # don't count the header line + tot_nRows -= 1 + + print("Writing sto file {} with name {} ({} muscles)".format(f_sto, name, len(fs_csv))) if maxtime != DEFAULT_MAXTIME: print("Scaling to maxtime {}".format(maxtime)) @@ -119,8 +123,8 @@ def main(): fds_csv = [ open(f_csv, 'r') for f_csv in fs_csv ] crs = [ csv.reader(fd_csv, delimiter=',') for fd_csv in fds_csv ] - times = np.zeros((tot_nRows - 1, len(fds_csv))) - vals = np.zeros((tot_nRows - 1, len(fds_csv))) + times = np.zeros((tot_nRows, len(fds_csv))) + vals = np.zeros((tot_nRows, len(fds_csv))) for i, cr in enumerate(crs): cr.next() # skip header line for j, row in enumerate(cr): -- cgit v1.2.3-54-g00ecf '>range
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2016-05-20 17:04:08 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-20 17:58:30 -0700
commit481aea5c59a57123b66d5850be1be79f9f230c0e (patch)
tree5343816c79009d7c9427c3fbe27e7f6a24a402a9
parenta91e8994f242a500bf05b9ee96fcd7ab0228f05f (diff)
checkpatch: whine about ACCESS_ONCE
Add a test for use of ACCESS_ONCE that could be written using READ_ONCE or WRITE_ONCE. --fix it too if desired. The WRITE_ONCE fixes are less correct than the coccinelle script below as checkpatch cannot have a completely correct "expression" mechanism because checkpatch works on patches and not complete files. $ cat access_once.cocci @@ expression e1; expression e2; @@ - ACCESS_ONCE(e1) = e2 + WRITE_ONCE(e1, e2) @@ expression e1; @@ - ACCESS_ONCE(e1) + READ_ONCE(e1) Signed-off-by: Joe Perches <joe@perches.com> Cc: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>