Changeset 3928


Ignore:
Timestamp:
04/16/08 15:37:38 (12 years ago)
Author:
curtis
Message:

Code from Tom Caswell to parse timestamp for each image plane.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/in/ND2Reader.java

    r3925 r3928  
    4949 * 
    5050 * Also note that there is alternate ND2 reader for Windows 
    51  * (see LegacyND2Reader.java) that requires a native library.  If that native 
     51 * (see LegacyND2Reader.java) that requires a native library. If that native 
    5252 * library is installed, then ND2Reader's logic will be bypassed. 
     53 * 
     54 * Thanks to Tom Caswell for additions to the ND2 metadata parsing logic. 
    5355 * 
    5456 * <dl><dt><b>Source code:</b></dt> 
     
    151153  private Vector zs = new Vector(); 
    152154  private Vector ts = new Vector(); 
     155  private Vector tsT = new Vector(); 
    153156 
    154157  private int numSeries; 
     
    480483            } 
    481484          } 
     485          else if (len >= 12 && b[0] == 'C' && b[1] == 'u' && b[2] == 's' && 
     486            b[3] == 't' && b[4] == 'o' && b[5] == 'm' && b[6] == 'D' && 
     487            b[7] == 'a' && b[8] == 't' && b[9] == 'a'&&b[10]=='|'&&b[11]=='A') 
     488            // b.startsWith("CustomData|A") 
     489          { 
     490            // the acqtimecache is a undeliniated stream of doubles 
     491            int off = 0; 
     492            for (int i=0; i<len; i++) { 
     493              char c = (char) b[i]; 
     494              if ((off == 0 && c == '!')) off = i + 1; 
     495            } 
     496            for (int j = off; j<len; j+=8) { 
     497              tsT.add(new Double(arr2double(b, j))); 
     498            } 
     499            addMeta("ts_t", tsT); 
     500            // adds the whole vector of times to the meta data 
     501            // I do not know if this will run in to trouble with the 
     502            // size limits on the length of strings in the hash table 
     503            addMeta("ts_t_sz", new Integer(tsT.size())); 
     504            // adds the length of the acq time vector to the hash table 
     505            // as a double check 
     506          } 
    482507 
    483508          if (core.imageCount[0] > 0 && offsets == null) { 
     
    520545            offsets[i][j] = tmpOffsets[j][i]; 
    521546          } 
    522         }  
     547        } 
    523548      } 
    524549      else if (offsets.length != core.imageCount.length) { 
     
    600625//        } 
    601626      } 
     627      //addMeta("ts", ts.elementAt(25)); 
     628      //addMeta("tssz", new Integer(ts.size())); 
    602629 
    603630      return; 
     
    9971024      if (!ts.contains(new Long(v))) { 
    9981025        ts.add(new Long(v)); 
     1026        addMeta("changes", new Integer(ts.size())); 
    9991027      } 
    10001028    } 
     
    10611089  } 
    10621090 
     1091  /** 
     1092   * Helper function for parsing acq times. 
     1093   * Code from http://www.captain.at/howto-java-convert-binary-data.php 
     1094   */ 
     1095  private double arr2double(byte[] arr, int start) { 
     1096    // I am not sure what the protocol on this is 
     1097    int i = 0; 
     1098    int len = 8; 
     1099    int cnt = 0; 
     1100    byte[] tmp = new byte[len]; 
     1101    for (i = start; i < (start + len); i++) { 
     1102      tmp[cnt] = arr[i]; 
     1103      cnt++; 
     1104    } 
     1105    long accum = 0; 
     1106    i = 0; 
     1107    for (int shiftBy = 0; shiftBy < 64; shiftBy += 8) { 
     1108      accum |= ((long) (tmp[i] & 0xff)) << shiftBy; 
     1109      i++; 
     1110    } 
     1111    return Double.longBitsToDouble(accum); 
     1112  } 
     1113 
    10631114} 
Note: See TracChangeset for help on using the changeset viewer.