gt:     byte[] mmheader = shortArrayToBytes(s);
context: /*
   * #%L
   * OME Bio-Formats package for reading and converting biological file formats.
   * %%
   * Copyright (C) 2005 - 2016 Open Microscopy Environment:
   *   - Board of Regents of the University of Wisconsin-Madison
   *   - Glencoe Software, Inc.
   *   - University of Dundee
   * %%
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as
   * published by the Free Software Foundation, either version 2 of the 
   * License, or (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public 
   * License along with this program.  If not, see
   * <http://www.gnu.org/licenses/gpl-2.0.html>.
   * #L%
   */
  
  package loci.formats.in;
  
  import java.io.IOException;
  import java.math.BigDecimal;
  import java.math.MathContext;
  import java.math.RoundingMode;
  import java.util.ArrayList;
  
  import loci.common.DateTools;
  import loci.common.RandomAccessInputStream;
  import loci.formats.CoreMetadata;
  import loci.formats.FormatException;
  import loci.formats.FormatTools;
  import loci.formats.MetadataTools;
  import loci.formats.meta.MetadataStore;
  import loci.formats.tiff.IFD;
  import loci.formats.tiff.TiffParser;
  import loci.formats.tiff.TiffRational;
  import ome.xml.model.primitives.PositiveFloat;
  import ome.xml.model.primitives.Timestamp;
  import ome.units.quantity.ElectricPotential;
  import ome.units.quantity.Frequency;
  import ome.units.quantity.Length;
  import ome.units.quantity.Temperature;
  import ome.units.quantity.Time;
  import ome.units.UNITS;
  
  /**
   * FluoviewReader is the file format reader for
   * Olympus Fluoview TIFF files AND Andor Bio-imaging Division (ABD) TIFF files.
   *
   * @author Eric Kjellman egkjellman at wisc.edu
   * @author Melissa Linkert melissa at glencoesoftware.com
   * @author Curtis Rueden ctrueden at wisc.edu
   */
  public class FluoviewReader extends BaseTiffReader {
  
    // -- Constants --
  
    /** String identifying a Fluoview file. */
    private static final String FLUOVIEW_MAGIC_STRING = "FLUOVIEW";
    private static final String ANDOR_MAGIC_STRING = "Andor";
  
    /** Private TIFF tags */
    private static final int MMHEADER = 34361;
    private static final int MMSTAMP = 34362;
  
    private static final int TEMPERATURE = 4869;
    private static final int EXPOSURE_TIME = 4876;
    private static final int KINETIC_CYCLE_TIME = 4878;
    private static final int N_ACCUMULATIONS = 4879;
    private static final int ACQUISITION_CYCLE_TIME = 4881;
    private static final int READOUT_TIME = 4882;
    private static final int EM_DAC = 4885;
    private static final int N_FRAMES = 4890;
    private static final int HORIZONTAL_FLIP = 4896;
    private static final int VERTICAL_FLIP = 4897;
    private static final int CLOCKWISE = 4898;
    private static final int COUNTER_CLOCKWISE = 4899;
    private static final int VERTICAL_CLOCK_VOLTAGE = 4904;
    private static final int VERTICAL_SHIFT_SPEED = 4905;
    private static final int PRE_AMP_SETTING = 4907;
    private static final int CAMERA_SERIAL_SETTING = 4908;
    private static final int ACTUAL_TEMPERATURE = 4911;
    private static final int BASELINE_CLAMP = 4912;
    private static final int PRESCANS = 4913;
    private static final int MODEL = 4914;
    private static final int CHIP_SIZE_X = 4915;
    private static final int CHIP_SIZE_Y = 4916;
    private static final int BASELINE_OFFSET = 4944;
  
    /** Date format */
    private static final String DATE_FORMAT = "MM/dd/yyyy HH:mm:ss.SSS";
  
    // -- Fields --
  
    /** Pixel dimensions for this file. */
    private double voxelX = 1, voxelY = 1, voxelZ = 1, voxelC = 1, voxelT = 1;
  
    private String dimensionOrder;
    private String date = null;
    private int timeIndex = -1;
    private int fieldIndex = -1;
    private int montageIndex = -1;
  
    /** Timestamps for each plane, in seconds. */
    private double[][] stamps = null;
    private double[] zPositions = null;
    
    // hardware settings
    private String[] gains, voltages, offsets, channelNames, lensNA;
    private String mag, detectorManufacturer, objectiveManufacturer, comment;
  
    private Float temperature, exposureTime, readoutTime;
    private String model;
  
    private double[][] montageOffsets;
    private double[][] fieldOffsets;
  
    // -- Constructor --
  
    /** Constructs a new Fluoview TIFF reader. */
    public FluoviewReader() {
      super("Olympus Fluoview/ABD TIFF", new String[] {"tif", "tiff"});
      suffixSufficient = false;
      domains = new String[] {FormatTools.LM_DOMAIN};
      datasetDescription =
        "One or more .tif/.tiff files, and an optional .txt file";
    }
  
    // -- IFormatReader API methods --
  
    /* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
    @Override
    public boolean isThisType(RandomAccessInputStream stream) throws IOException {
      TiffParser tp = new TiffParser(stream);
      IFD ifd = tp.getFirstIFD();
      if (ifd == null) return false;
      String com = ifd.getComment();
      if (com == null) com = "";
      return (com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 &&
        ifd.containsKey(new Integer(MMHEADER)) ||
        ifd.containsKey(new Integer(MMSTAMP))) ||
        com.startsWith(ANDOR_MAGIC_STRING);
    }
  
    /**
     * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
     */
    @Override
    public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
      throws FormatException, IOException
    {
      int image = getImageIndex(no);
  
      if (tiffParser == null) {
        initTiffParser();
      }
  
      if (getSizeY() == ifds.get(0).getImageLength()) {
        tiffParser.getSamples(ifds.get(image), buf, x, y, w, h);
      }
      else {
        FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
        tiffParser.getSamples(ifds.get(0), buf, x, image, w, 1);
      }
  
      return buf;
    }
  
    /* @see loci.formats.IFormatReader#close(boolean) */
    @Override
    public void close(boolean fileOnly) throws IOException {
      super.close(fileOnly);
      if (!fileOnly) {
        voxelX = voxelY = voxelZ = voxelC = voxelT = 1;
        dimensionOrder = null;
        gains = voltages = offsets = channelNames = lensNA = null;
        mag = detectorManufacturer = objectiveManufacturer = comment = null;
        date = null;
        timeIndex = -1;
        stamps = null;
        fieldIndex = -1;
        montageIndex = -1;
        fieldOffsets = null;
        montageOffsets = null;
        model = null;
        temperature = null;
        exposureTime = null;
        readoutTime = null;
      }
    }
  
    // -- Internal BaseTiffReader API methods --
  
    /* @see loci.formats.BaseTiffReader#initStandardMetadata() */
    @Override
    protected void initStandardMetadata() throws FormatException, IOException {
      super.initStandardMetadata();
  
      // First, we want to determine whether this file is a Fluoview TIFF.
      // Originally, Andor TIFF had its own reader; however, the two formats are
      // very similar, so it made more sense to merge the two formats into one
      // reader.
  
      short[] s = ifds.get(0).getIFDShortArray(MMHEADER);
      if (s == null) {
        initAlternateMetadata();
        return;
      }
  