]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #3659
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 30 Aug 2012 14:19:57 +0000 (14:19 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 30 Aug 2012 14:19:57 +0000 (14:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25552 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/META-INF/MANIFEST.MF
org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java

index a3c07a6aeaa236e5f006a7857ded29a3c438af6a..7fd8c199cdf7b328928799fc7e4c25d879093f0f 100644 (file)
@@ -9,7 +9,8 @@ Require-Bundle: gnu.trove2;bundle-version="2.0.4",
  org.eclipse.core.runtime;bundle-version="3.6.0",
  org.simantics.history;bundle-version="1.0.0",
  org.simantics.databoard;bundle-version="0.6.3",
- org.simantics.utils;bundle-version="1.1.0"
+ org.simantics.utils;bundle-version="1.1.0",
+ org.simantics.utils.datastructures;bundle-version="1.1.0"
 Export-Package: org.simantics.modelica,
  org.simantics.modelica.data,
  org.simantics.modelica.fmi,
index 032dbc440d20cae242a23cd92e0dc8e519c495ec..84b20e642330da89b1391d5ba7c44aebb80f6367 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.modelica.data.DoubleMatrix;
 import org.simantics.modelica.data.IntMatrix;\r
 import org.simantics.modelica.data.Matrix;\r
 import org.simantics.modelica.data.StringMatrix;\r
+import org.simantics.utils.datastructures.MapList;\r
 \r
 public class MatFileReader implements ResultFileReader {\r
        private File file;\r
@@ -380,28 +381,36 @@ public class MatFileReader implements ResultFileReader {
                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[size];\r
+                       //vs[i] = new double[size];\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
+               //Map<Integer, Integer> cToRow = new HashMap<Integer, Integer>();\r
+               MapList<Integer, Integer> cToRow = new MapList<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
+                       //cToRow.put(uc[i], unSortedRows.get(i));\r
+                       cToRow.add(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
+//             int sc[] = new int[unSortedRows.size()];\r
+//             int c[] = new int[unSortedRows.size()];\r
+               int sc[] = new int[sortedCs.size()];\r
+               int c[] = new int[sortedCs.size()];\r
                \r
                Collections.sort(sortedCs);\r
-               for (int i = 0; i < unSortedRows.size(); i++) {\r
-                       int row = cToRow.get(sortedCs.get(i));\r
+\r
+               //for (int i = 0; i < unSortedRows.size(); i++) {\r
+               for (int i = 0; i < sortedCs.size(); i++) {\r
+                       //int row = cToRow.get(sortedCs.get(i));\r
+                       int row = cToRow.getValues(sortedCs.get(i)).get(0);\r
                        sortedRows.add(row);\r
                        sc[i] = usc[unSortedRows.indexOf(row)];\r
                        c[i] = uc[unSortedRows.indexOf(row)];\r
+                       vs[i] = new double[size];\r
                }\r
        \r
                \r
@@ -430,16 +439,37 @@ public class MatFileReader implements ResultFileReader {
                  vs[i][j] = -vs[i][j];\r
          \r
        }\r
-       for (int i = 0; i < sortedRows.size(); i++) {\r
-               int row = sortedRows.get(i);\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
+       for (int i = 0; i < unSortedRows.size(); i++) {\r
                int rRow = unSortedRows.get(i);\r
-               if (row != rRow) {\r
-                       int ri = sortedRows.indexOf(rRow);\r
-                       double v[] = vs[i];\r
+               \r
+               if (i < sortedRows.size())  {\r
+                       int row = sortedRows.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
+               } else {\r
+                       int uci = uc[i];\r
+                       int row = cToRow.getValues(uci).get(0);\r
+                       int ri = sortedRows.indexOf(row);\r
                        vs[i] = vs[ri];\r
-                       vs[ri] = v;\r
-                       sortedRows.set(i, rRow);\r
-                       sortedRows.set(ri, row);\r
                }\r
        }\r
        \r
@@ -471,45 +501,40 @@ public class MatFileReader implements ResultFileReader {
                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
+                       //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
+               //Map<Integer, Integer> cToRow = new HashMap<Integer, Integer>();\r
+               MapList<Integer, Integer> cToRow = new MapList<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
+                       //cToRow.put(uc[i], unSortedRows.get(i));\r
+                       cToRow.add(uc[i], unSortedRows.get(i));\r
+                       if (!sortedCs.contains(uc[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
+//             int sc[] = new int[unSortedRows.size()];\r
+//             int c[] = new int[unSortedRows.size()];\r
+               int sc[] = new int[sortedCs.size()];\r
+               int c[] = new int[sortedCs.size()];\r
                \r
                Collections.sort(sortedCs);\r
-               for (int i = 0; i < unSortedRows.size(); i++) {\r
-                       int row = cToRow.get(sortedCs.get(i));\r
+               //for (int i = 0; i < unSortedRows.size(); i++) {\r
+               for (int i = 0; i < sortedCs.size(); i++) {\r
+                       //int row = cToRow.get(sortedCs.get(i));\r
+                       int row = cToRow.getValues(sortedCs.get(i)).get(0);\r
                        sortedRows.add(row);\r
                        sc[i] = usc[unSortedRows.indexOf(row)];\r
                        c[i] = uc[unSortedRows.indexOf(row)];\r
+                       vs[i] = new double[count];\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
@@ -537,16 +562,25 @@ public class MatFileReader implements ResultFileReader {
                  vs[i][j] = -vs[i][j];\r
          \r
        }\r
-       for (int i = 0; i < sortedRows.size(); i++) {\r
-               int row = sortedRows.get(i);\r
+       for (int i = 0; i < unSortedRows.size(); i++) {\r
                int rRow = unSortedRows.get(i);\r
-               if (row != rRow) {\r
-                       int ri = sortedRows.indexOf(rRow);\r
-                       double v[] = vs[i];\r
+               \r
+               if (i < sortedRows.size())  {\r
+                       int row = sortedRows.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
+               } else {\r
+                       int uci = uc[i];\r
+                       int row = cToRow.getValues(uci).get(0);\r
+                       int ri = sortedRows.indexOf(row);\r
                        vs[i] = vs[ri];\r
-                       vs[ri] = v;\r
-                       sortedRows.set(i, rRow);\r
-                       sortedRows.set(ri, row);\r
                }\r
        }\r
        \r