\r
}\r
\r
+ @Override\r
+ public double[][] readData(List<String> items, int start, int count,\r
+ int skip) throws IOException {\r
+ readBytes = 0;\r
+ \r
+ List<Integer> indexes = new ArrayList<Integer>(items.size());\r
+ for (String item : items) {\r
+ Integer index = indices.get(item);\r
+ if (index == null)\r
+ throw new IOException("Unknown item: " + item);\r
+ indexes.add(index);\r
+ }\r
+ \r
+ InputStream in = new FileInputStream(file);\r
+ skip(dataMark, in);\r
+ \r
+ \r
+ \r
+ Object data = readRows(dataHeader, indexes,start,count,skip, in);\r
+ \r
+ in.close();\r
+ \r
+ return (double[][])data;\r
+ }\r
+ \r
\r
private void readVariables() throws IOException {\r
InputStream in = new FileInputStream(file);\r
return vs;\r
}\r
\r
+ \r
+ private double[][] readRows(MatrixHeader header, List<Integer> unSortedRows, int start, int count, int skip, InputStream in)throws IOException {\r
+\r
+ \r
+ ;\r
+ \r
+ if (header.type != 0)\r
+ throw new IOException("Only double type supported");\r
+ for (int row : unSortedRows)\r
+ if (infoData[row * 4] != 2)\r
+ throw new IOException(); // this is checked in initialization phase.\r
+ \r
+ \r
+ \r
+ int size = header.columns;\r
+ int rows = header.rows;\r
+ \r
+ if (start+count*(skip+1) > size)\r
+ throw new IndexOutOfBoundsException(); // TODO: we could just read available data, instead of throwing exception.\r
+ \r
+ int usc[] = new int[unSortedRows.size()];\r
+ int uc[] = new int[unSortedRows.size()];\r
+ double vs[][] = new double[unSortedRows.size()][];\r
+ for (int i = 0; i < unSortedRows.size(); i++) {\r
+ int row = unSortedRows.get(i);\r
+ vs[i] = new double[count];\r
+ usc[i] = infoData[row * 4 + 1];\r
+ uc[i] = usc[i] > 0 ? usc[i]-1 : 1-usc[i];\r
+ }\r
+ \r
+ Map<Integer, Integer> cToRow = new HashMap<Integer, Integer>();\r
+ List<Integer> sortedCs = new ArrayList<Integer>();\r
+ for (int i = 0; i < unSortedRows.size(); i++) {\r
+ cToRow.put(uc[i], unSortedRows.get(i));\r
+ sortedCs.add(uc[i]);\r
+ }\r
+ \r
+ List<Integer> sortedRows = new ArrayList<Integer>();\r
+ int sc[] = new int[unSortedRows.size()];\r
+ int c[] = new int[unSortedRows.size()];\r
+ \r
+ Collections.sort(sortedCs);\r
+ for (int i = 0; i < unSortedRows.size(); i++) {\r
+ int row = cToRow.get(sortedCs.get(i));\r
+ sortedRows.add(row);\r
+ sc[i] = usc[unSortedRows.indexOf(row)];\r
+ c[i] = uc[unSortedRows.indexOf(row)];\r
+ }\r
+ \r
+ \r
+ \r
+// skip((c+start*rows) * 8, in);\r
+// for (int j = 0; j < v.length; ++j) {\r
+// \r
+// double d = getDouble(in);\r
+// v[j] = d;\r
+// skip((rows*skip + rows-1)*8,in);\r
+// }\r
+//\r
+// \r
+// if(sc < 0)\r
+// for(int j=0;j<v.length;++j)\r
+// v[j] = -v[j];\r
+// return v;\r
+ \r
+ skip((start*rows) * 8, in);\r
+ skip(c[0] * 8, in);\r
+ for (int j = 0; j < count; ++j) {\r
+ for (int index = 0; index < sortedRows.size(); index++) {\r
+ \r
+ double d = getDouble(in);\r
+ vs[index][j] = d;\r
+ \r
+ if (index < sortedRows.size() - 1) {\r
+ skip((c[index+1] - c[index] -1 )*8, in);\r
+ } else {\r
+ skip((rows - c[index]-1 + c[0])*8,in);\r
+ }\r
+ //skip((rows-1)*8,in);\r
+ }\r
+ if (skip > 0)\r
+ skip((skip*rows)*8,in);\r
+ }\r
+\r
+ \r
+ for (int i = 0; i < sortedRows.size(); i++) {\r
+ if(sc[i] < 0)\r
+ for(int j=0;j<vs[i].length;++j)\r
+ vs[i][j] = -vs[i][j];\r
+ \r
+ }\r
+ for (int i = 0; i < sortedRows.size(); i++) {\r
+ int row = sortedRows.get(i);\r
+ int rRow = unSortedRows.get(i);\r
+ if (row != rRow) {\r
+ int ri = sortedRows.indexOf(rRow);\r
+ double v[] = vs[i];\r
+ vs[i] = vs[ri];\r
+ vs[ri] = v;\r
+ sortedRows.set(i, rRow);\r
+ sortedRows.set(ri, row);\r
+ }\r
+ }\r
+ \r
+ return vs;\r
+ }\r
private void skip(int skipBytes, InputStream in) throws IOException {\r
int skip = 0; \r
while (skip < skipBytes) {\r