<commit_before>//
// CellWorxReader.java
//

/*
OME Bio-Formats package for reading and converting biological file formats.
Copyright (C) 2005-@year@ UW-Madison LOCI and Glencoe Software, Inc.

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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.formats.in;

import java.io.IOException;
import java.util.Arrays;
import java.util.Vector;

import loci.common.DataTools;
import loci.common.DateTools;
import loci.common.Location;
import loci.common.RandomAccessInputStream;
import loci.formats.CoreMetadata;
import loci.formats.FormatException;
import loci.formats.FormatReader;
import loci.formats.FormatTools;
import loci.formats.IFormatReader;
import loci.formats.MetadataTools;
import loci.formats.meta.MetadataStore;

import ome.xml.model.primitives.NonNegativeInteger;
import ome.xml.model.primitives.PositiveFloat;
import ome.xml.model.primitives.PositiveInteger;

/**
 * CellWorxReader is the file format reader for CellWorx .pnl files.
 *
 * <dl><dt><b>Source code:</b></dt>
 * <dd><a href="http://trac.openmicroscopy.org.uk/ome/browser/bioformats.git/components/bio-formats/src/loci/formats/in/CellWorxReader.java">Trac</a>,
 * <a href="http://git.openmicroscopy.org/?p=bioformats.git;a=blob;f=components/bio-formats/src/loci/formats/in/CellWorxReader.java;hb=HEAD">Gitweb</a></dd></dl>
 */
public class CellWorxReader extends FormatReader {

  // -- Constants --

  private static final String DATE_FORMAT = "EEE MMM dd HH:mm:ss yyyy";

  // -- Fields --

  private boolean[][] fieldMap;
  private String[][][] wellFiles;
  private String[][] logFiles;
  private int fieldCount = 0;
  private boolean doChannels = false;

  private String plateLogFile;
  private String zMapFile;

  private String lastFile;
  private IFormatReader lastReader;

  // -- Constructor --

  /** Constructs a new CellWorx reader. */
  public CellWorxReader() {
    super("CellWorx", new String[] {"pnl", "htd", "log"});
    domains = new String[] {FormatTools.HCS_DOMAIN};
    hasCompanionFiles = true;
    datasetDescription = "One .htd file plus one or more .pnl or " +
      ".tif files and optionally one or more .log files";
  }

  // -- IFormatReader API methods --

  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */
  public boolean isThisType(String name, boolean open) {
    if (checkSuffix(name, "pnl") || checkSuffix(name, "htd")) {
      return super.isThisType(name, open);
    }
    if (!open) return false;

    boolean foundHTD = false;

    Location current = new Location(name).getAbsoluteFile();
    Location parent = current.getParentFile();

    String htdName = current.getName();
    while (htdName.indexOf("_") > 0) {
      htdName = htdName.substring(0, htdName.lastIndexOf("_"));
      if (new Location(parent, htdName + ".htd").exists() ||
        new Location(parent, htdName + ".HTD").exists())
      {
        return true;
      }
    }
    return false;
  }

  /* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
  public String[] getSeriesUsedFiles(boolean noPixels) {
    FormatTools.assertId(currentId, true, 1);
    Vector<String> files = new Vector<String>();
    files.add(currentId);
    if (plateLogFile != null && new Location(plateLogFile).exists()) {
      files.add(plateLogFile);
    }
    if (zMapFile != null) files.add(zMapFile);

    int row = getWellRow(getSeries());
    int col = getWellColumn(getSeries());

    if (new Location(logFiles[row][col]).exists()) {
      files.add(logFiles[row][col]);
    }
    if (!noPixels) {
      if (checkSuffix(wellFiles[row][col][0], "pnl")) {
        files.add(wellFiles[row][col][0]);
      }
      else {
        for (String f : wellFiles[row][col]) {
          files.add(f);
        }
      }
    }
    return files.toArray(new String[files.size()]);
  }

  /**
   * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
   */
  public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
    throws FormatException, IOException
  {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    int fieldIndex = getSeries() % fieldCount;

    String file = getFile(getSeries(), no);
    if (file == null) {
      Arrays.fill(buf, (byte) 0);
      return buf;
    }

    if (lastFile == null || lastReader == null || !file.equals(lastFile)) {
      if (lastReader != null) {
        lastReader.close();
      }<commit_msg>Only report used files that actually exist<commit_after>//
// CellWorxReader.java
//

/*
OME Bio-Formats package for reading and converting biological file formats.
Copyright (C) 2005-@year@ UW-Madison LOCI and Glencoe Software, Inc.

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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.formats.in;

import java.io.IOException;
import java.util.Arrays;
import java.util.Vector;

import loci.common.DataTools;
import loci.common.DateTools;
import loci.common.Location;
import loci.common.RandomAccessInputStream;
import loci.formats.CoreMetadata;
import loci.formats.FormatException;
import loci.formats.FormatReader;
import loci.formats.FormatTools;
import loci.formats.IFormatReader;
import loci.formats.MetadataTools;
import loci.formats.meta.MetadataStore;

import ome.xml.model.primitives.NonNegativeInteger;
import ome.xml.model.primitives.PositiveFloat;
import ome.xml.model.primitives.PositiveInteger;

/**
 * CellWorxReader is the file format reader for CellWorx .pnl files.
 *
 * <dl><dt><b>Source code:</b></dt>
 * <dd><a href="http://trac.openmicroscopy.org.uk/ome/browser/bioformats.git/components/bio-formats/src/loci/formats/in/CellWorxReader.java">Trac</a>,
 * <a href="http://git.openmicroscopy.org/?p=bioformats.git;a=blob;f=components/bio-formats/src/loci/formats/in/CellWorxReader.java;hb=HEAD">Gitweb</a></dd></dl>
 */
public class CellWorxReader extends FormatReader {

  // -- Constants --

  private static final String DATE_FORMAT = "EEE MMM dd HH:mm:ss yyyy";

  // -- Fields --

  private boolean[][] fieldMap;
  private String[][][] wellFiles;
  private String[][] logFiles;
  private int fieldCount = 0;
  private boolean doChannels = false;

  private String plateLogFile;
  private String zMapFile;

  private String lastFile;
  private IFormatReader lastReader;

  // -- Constructor --

  /** Constructs a new CellWorx reader. */
  public CellWorxReader() {
    super("CellWorx", new String[] {"pnl", "htd", "log"});
    domains = new String[] {FormatTools.HCS_DOMAIN};
    hasCompanionFiles = true;
    datasetDescription = "One .htd file plus one or more .pnl or " +
      ".tif files and optionally one or more .log files";
  }

  // -- IFormatReader API methods --

  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */
  public boolean isThisType(String name, boolean open) {
    if (checkSuffix(name, "pnl") || checkSuffix(name, "htd")) {
      return super.isThisType(name, open);
    }
    if (!open) return false;

    boolean foundHTD = false;

    Location current = new Location(name).getAbsoluteFile();
    Location parent = current.getParentFile();

    String htdName = current.getName();
    while (htdName.indexOf("_") > 0) {
      htdName = htdName.substring(0, htdName.lastIndexOf("_"));
      if (new Location(parent, htdName + ".htd").exists() ||
        new Location(parent, htdName + ".HTD").exists())
      {
        return true;
      }
    }
    return false;
  }

  /* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
  public String[] getSeriesUsedFiles(boolean noPixels) {
    FormatTools.assertId(currentId, true, 1);
    Vector<String> files = new Vector<String>();
    files.add(currentId);
    if (plateLogFile != null && new Location(plateLogFile).exists()) {
      files.add(plateLogFile);
    }
    if (zMapFile != null) files.add(zMapFile);

    int row = getWellRow(getSeries());
    int col = getWellColumn(getSeries());

    if (new Location(logFiles[row][col]).exists()) {
      files.add(logFiles[row][col]);
    }
    if (!noPixels) {
      if (checkSuffix(wellFiles[row][col][0], "pnl")) {
        if (new Location(wellFiles[row][col][0]).exists()) {
          files.add(wellFiles[row][col][0]);
        }
      }
      else {
        for (String f : wellFiles[row][col]) {
          if (new Location(f).exists()) {
            files.add(f);
          }
        }
      }
    }
    return files.toArray(new String[files.size()]);
  }

  /**
   * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
   */
  public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
    throws FormatException, IOException
  {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    int fieldIndex = getSeries() % fieldCount;

    String file = getFile(getSeries(), no);
    if (file == null) {
      Arrays.fill(buf, (byte) 0);
      return buf;
    }

    if (lastFile == null || lastReader == null || !file.equals(lastFile)) {
      if (lastReader != null) {
        lastReader.close();
      }
{'fraction_non_alphanumeric': 0.12980392156862744, 'fraction_numerical': 0.005196078431372549, 'mean_word_length': 3.556051808843234, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559675', 'n_tokens_mistral': 3324, 'n_tokens_neox': 3174, 'n_words': 878}