From: luukkainen Date: Tue, 7 Aug 2012 11:29:52 +0000 (+0000) Subject: Ability to make skipped & partial reads for multiple items at the same time. X-Git-Tag: simantics-1.7~6 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=29a8658cabc21f95986e096b6d8e9531260f3406;p=simantics%2Fsysdyn.git Ability to make skipped & partial reads for multiple items at the same time. refs #3544 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25395 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java b/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java index 9571ee34..49170171 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java +++ b/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java @@ -110,6 +110,31 @@ public class MatFileReader implements ResultFileReader { } + @Override + public double[][] readData(List items, int start, int count, + int skip) throws IOException { + readBytes = 0; + + List indexes = new ArrayList(items.size()); + for (String item : items) { + Integer index = indices.get(item); + if (index == null) + throw new IOException("Unknown item: " + item); + indexes.add(index); + } + + InputStream in = new FileInputStream(file); + skip(dataMark, in); + + + + Object data = readRows(dataHeader, indexes,start,count,skip, in); + + in.close(); + + return (double[][])data; + } + private void readVariables() throws IOException { InputStream in = new FileInputStream(file); @@ -415,6 +440,112 @@ public class MatFileReader implements ResultFileReader { return vs; } + + private double[][] readRows(MatrixHeader header, List unSortedRows, int start, int count, int skip, InputStream in)throws IOException { + + + ; + + if (header.type != 0) + throw new IOException("Only double type supported"); + for (int row : unSortedRows) + if (infoData[row * 4] != 2) + throw new IOException(); // this is checked in initialization phase. + + + + int size = header.columns; + int rows = header.rows; + + if (start+count*(skip+1) > size) + throw new IndexOutOfBoundsException(); // TODO: we could just read available data, instead of throwing exception. + + int usc[] = new int[unSortedRows.size()]; + int uc[] = new int[unSortedRows.size()]; + double vs[][] = new double[unSortedRows.size()][]; + for (int i = 0; i < unSortedRows.size(); i++) { + int row = unSortedRows.get(i); + vs[i] = new double[count]; + usc[i] = infoData[row * 4 + 1]; + uc[i] = usc[i] > 0 ? usc[i]-1 : 1-usc[i]; + } + + Map cToRow = new HashMap(); + List sortedCs = new ArrayList(); + for (int i = 0; i < unSortedRows.size(); i++) { + cToRow.put(uc[i], unSortedRows.get(i)); + sortedCs.add(uc[i]); + } + + List sortedRows = new ArrayList(); + int sc[] = new int[unSortedRows.size()]; + int c[] = new int[unSortedRows.size()]; + + Collections.sort(sortedCs); + for (int i = 0; i < unSortedRows.size(); i++) { + int row = cToRow.get(sortedCs.get(i)); + sortedRows.add(row); + sc[i] = usc[unSortedRows.indexOf(row)]; + c[i] = uc[unSortedRows.indexOf(row)]; + } + + + +// skip((c+start*rows) * 8, in); +// for (int j = 0; j < v.length; ++j) { +// +// double d = getDouble(in); +// v[j] = d; +// skip((rows*skip + rows-1)*8,in); +// } +// +// +// if(sc < 0) +// for(int j=0;j 0) + skip((skip*rows)*8,in); + } + + + for (int i = 0; i < sortedRows.size(); i++) { + if(sc[i] < 0) + for(int j=0;j items) throws IOException ; + + public double[][] readData(List items, int start, int count, int skip) throws IOException ; }