Revision: 21207
          http://sourceforge.net/p/jmol/code/21207
Author:   hansonr
Date:     2016-08-10 21:51:12 +0000 (Wed, 10 Aug 2016)
Log Message:
-----------
even simpler mmtf decoding

Modified Paths:
--------------
    branches/v14_6/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java
    trunk/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java

Modified: 
branches/v14_6/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java
===================================================================
--- branches/v14_6/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java 
2016-08-10 17:34:01 UTC (rev 21206)
+++ branches/v14_6/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java 
2016-08-10 21:51:12 UTC (rev 21207)
@@ -328,11 +328,11 @@
     int param = BC.bytesToInt(b, 8, true);
     switch (type) {
     case 1:
-      return getFloats(b, 4, 1);
+      return getFloats(b, n, 1);
     case 2: // 1-byte
     case 3: // 2-byte
     case 4: // 4-byte
-      return getInts(b, 1 << (type - 2));
+      return getInts(b, n);
     case 5:
       return rldecode32ToStr(b);
     case 6:
@@ -346,7 +346,7 @@
     case 10:
       return unpack16Deltaf(b, n, param);
     case 11:
-      return getFloats(b, 2, param);
+      return getFloats(b, n, param);
     case 12: // two-byte
     case 13: // one-byte
       return unpackf(b, 14 - type, n, param);
@@ -372,16 +372,15 @@
   public static float[] getFloats(byte[] b, int n, float divisor) {
     if (b == null)
       return null;
-    int len = (b.length - 12) / n;
-    float[] a = new float[len];
+    float[] a = new float[n];
     try {
-      switch (n) {  
+      switch ((b.length - 12) / n) {  
       case 2:
-        for (int i = 0, j = 12; i < len; i++, j += 2)
+        for (int i = 0, j = 12; i < n; i++, j += 2)
           a[i] = BC.bytesToShort(b, j, false) / divisor;
         break;
       case 4:
-        for (int i = 0, j = 12; i < len; i++, j += 4)
+        for (int i = 0, j = 12; i < n; i++, j += 4)
           a[i] = BC.bytesToFloat(b, j, false);
         break;
       }
@@ -396,27 +395,25 @@
    * Decode a byte array into a byte, short, or int array.
    * 
    * @param b
-   * @param nbytes
-   *        1 (byte), 2 (int16), or 4 (int32)
+   * @param n
    *        
    * @return array of integers
    */
-  public static int[] getInts(byte[] b, int nbytes) {
+  public static int[] getInts(byte[] b, int n) {
     if (b == null)
       return null;
-    int len = (b.length - 12) / nbytes;
-    int[] a = new int[len];
-    switch (nbytes) {
+    int[] a = new int[n];
+    switch ((b.length - 12) / n) {
     case 1:
-      for (int i = 0, j = 12; i < len; i++, j++)
+      for (int i = 0, j = 12; i < n; i++, j++)
         a[i] = b[j];
       break;
     case 2:
-      for (int i = 0, j = 12; i < len; i++, j += 2)
+      for (int i = 0, j = 12; i < n; i++, j += 2)
         a[i] = BC.bytesToShort(b, j, true);
       break;
     case 4:
-      for (int i = 0, j = 12; i < len; i++, j += 4)
+      for (int i = 0, j = 12; i < n; i++, j += 4)
         a[i] = BC.bytesToInt(b, j, true);
       break;
     }
@@ -520,7 +517,8 @@
   /**
    * mmtf type 9
    * 
-   * Decode an array of int32 using run-length decoding.
+   * Decode an array of int32 using run-length decoding and divide by a divisor
+   * to give a float32.
    * 
    * @param b
    * @param n

Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java  
2016-08-10 17:34:01 UTC (rev 21206)
+++ trunk/Jmol/src/org/jmol/adapter/readers/cif/MessagePackReader.java  
2016-08-10 21:51:12 UTC (rev 21207)
@@ -328,11 +328,11 @@
     int param = BC.bytesToInt(b, 8, true);
     switch (type) {
     case 1:
-      return getFloats(b, 4, 1);
+      return getFloats(b, n, 1);
     case 2: // 1-byte
     case 3: // 2-byte
     case 4: // 4-byte
-      return getInts(b, 1 << (type - 2));
+      return getInts(b, n);
     case 5:
       return rldecode32ToStr(b);
     case 6:
@@ -346,7 +346,7 @@
     case 10:
       return unpack16Deltaf(b, n, param);
     case 11:
-      return getFloats(b, 2, param);
+      return getFloats(b, n, param);
     case 12: // two-byte
     case 13: // one-byte
       return unpackf(b, 14 - type, n, param);
@@ -372,16 +372,15 @@
   public static float[] getFloats(byte[] b, int n, float divisor) {
     if (b == null)
       return null;
-    int len = (b.length - 12) / n;
-    float[] a = new float[len];
+    float[] a = new float[n];
     try {
-      switch (n) {  
+      switch ((b.length - 12) / n) {  
       case 2:
-        for (int i = 0, j = 12; i < len; i++, j += 2)
+        for (int i = 0, j = 12; i < n; i++, j += 2)
           a[i] = BC.bytesToShort(b, j, false) / divisor;
         break;
       case 4:
-        for (int i = 0, j = 12; i < len; i++, j += 4)
+        for (int i = 0, j = 12; i < n; i++, j += 4)
           a[i] = BC.bytesToFloat(b, j, false);
         break;
       }
@@ -396,27 +395,25 @@
    * Decode a byte array into a byte, short, or int array.
    * 
    * @param b
-   * @param nbytes
-   *        1 (byte), 2 (int16), or 4 (int32)
+   * @param n
    *        
    * @return array of integers
    */
-  public static int[] getInts(byte[] b, int nbytes) {
+  public static int[] getInts(byte[] b, int n) {
     if (b == null)
       return null;
-    int len = (b.length - 12) / nbytes;
-    int[] a = new int[len];
-    switch (nbytes) {
+    int[] a = new int[n];
+    switch ((b.length - 12) / n) {
     case 1:
-      for (int i = 0, j = 12; i < len; i++, j++)
+      for (int i = 0, j = 12; i < n; i++, j++)
         a[i] = b[j];
       break;
     case 2:
-      for (int i = 0, j = 12; i < len; i++, j += 2)
+      for (int i = 0, j = 12; i < n; i++, j += 2)
         a[i] = BC.bytesToShort(b, j, true);
       break;
     case 4:
-      for (int i = 0, j = 12; i < len; i++, j += 4)
+      for (int i = 0, j = 12; i < n; i++, j += 4)
         a[i] = BC.bytesToInt(b, j, true);
       break;
     }
@@ -520,7 +517,8 @@
   /**
    * mmtf type 9
    * 
-   * Decode an array of int32 using run-length decoding.
+   * Decode an array of int32 using run-length decoding and divide by a divisor
+   * to give a float32.
    * 
    * @param b
    * @param n

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to