Ejemplo n.º 1
0
    public PlugInChannelMap CT2PImap(
        PlugInChannelMap picm, CTmap ctmap, double tget, double tdur, String tmode) {
      int nchan = ctmap.size();
      try {
        for (int i = 0; i < nchan; i++) {
          String cname = ctmap.getName(i);
          picm.Add(cname);
          CTdata td;
          //					if(tmode.equals("absolute")) td = ctmap.getTimeData(cname, tget, tdur);	// use
          // tget,tdur for trim
          //					else						 td = ctmap.getTimeData(cname);
          if (debug)
            System.err.println(
                "getTimeData, tget: " + tget + ", tdur: " + tdur + ", tmode: " + tmode);
          //					td = ctmap.getTimeData(cname, tget, tdur, tmode);
          td = ctmap.getTimeData(cname); // already trimmed MJM 4/27/16
          if (debug)
            System.err.println(
                "cname: "
                    + cname
                    + ", fileType: "
                    + CTinfo.fileType(cname, typeDefault)
                    + ", td.size: "
                    + td.size());
          if (td == null || td.size() == 0) continue; // no data found this time

          td.setSwap(swapFlag);
          char fileType = CTinfo.fileType(cname, typeDefault);

          if (fileType != 'B') picm.PutTimes(td.getTime()); // doesn't work with byte[][]
          //				System.err.println("PutTimes len: "+td.getTime().length);
          switch (fileType) {
            case 'F':
              picm.PutDataAsFloat64(i, td.getDataAsFloat64());
              break;
            case 'f':
              picm.PutDataAsFloat32(i, td.getDataAsFloat32());
              break;
            case 'I':
              picm.PutDataAsInt64(i, td.getDataAsInt64());
              break;
            case 'i':
              picm.PutDataAsInt32(i, td.getDataAsInt32());
              break;
            case 'j':
              picm.PutDataAsInt16(i, td.getDataAsInt16());
              break;
            case 'n':
              picm.PutDataAsFloat32(i, td.getDataAsNumericF32());
              break;
            case 'N':
              picm.PutDataAsFloat64(i, td.getDataAsNumericF64());
              break;
            case 'B':
            default:
              if (debug) System.err.println("PutByte[] len: " + td.size());
              double[] time = td.getTime();
              byte[][] bdata = td.getData();
              for (int j = 0; j < td.size(); j++) {
                picm.PutTime(time[j], 0.);
                picm.PutDataAsByteArray(i, bdata[j]);
              }
              break;
          }
        }
      } catch (Exception e) {
        System.err.println("CTplugin Exception: " + e);
        //				e.printStackTrace();
        return null;
      }
      return picm;
    }
Ejemplo n.º 2
0
  // **********************  PlugInTemplate Overrides  *************************//
  protected void processRequest(ChannelMap fwdData, PlugInChannelMap out) throws SAPIException {
    if (fwdData.NumberOfChannels() == 0) return;

    // Override member defaults with dynamic options:
    int minDecimation = this.minDecimation, maxSamples = this.maxSamples;
    boolean antiAlias = this.antiAlias;

    java.util.Properties opts = getRequestOptions();
    String temp;
    if ((temp = opts.getProperty("minDecimation")) != null) minDecimation = Integer.parseInt(temp);
    if ((temp = opts.getProperty("maxSamples")) != null) maxSamples = Integer.parseInt(temp);
    if ((temp = opts.getProperty("antiAlias")) != null) antiAlias = "true".equals(temp);

    // 2007/08/15  WHF  maxSamples applies to all channels:
    // 2007/08/15  WHF  Changed their mind.  Uncomment to re-enable.
    /*if (fwdData.NumberOfChannels() == 0) return;
    maxSamples /= fwdData.NumberOfChannels();
    if (maxSamples < 1) maxSamples = 1; */

    for (int index = 0; index < fwdData.NumberOfChannels(); ++index) {
      Object data;

      // Will add if necessary, otherwise just a lookup:
      int outIndex = out.Add(fwdData.GetName(index));

      // data = GetDataAsArray.get(fwdData, index);
      data = fwdData.GetDataAsArray(index);
      if (data == null) {
        System.err.println("ResamplePlugIn: Unsupported datatype.");
        continue;
      }

      int npts = Array.getLength(data);

      if (npts <= maxSamples && minDecimation < 2) {
        // length okay, just copy:
        out.PutTimeRef(fwdData, index);
        out.PutDataRef(outIndex, fwdData, index);
        continue;
      }

      // Calculate the decimation factor for this set:
      int ndeci = (int) Math.ceil(((double) npts) / maxSamples);
      if (ndeci < minDecimation) ndeci = minDecimation;

      double[] ddata = null;
      if (antiAlias) {
        if (fwdData.GetType(index) == ChannelMap.TYPE_FLOAT64) {
          ddata = (double[]) data;
        } else {
          ddata = new double[npts];
          for (int ii = 0; ii < npts; ++ii) ddata[ii] = Array.getDouble(data, ii);
        }
        double[] dataOut = new double[ddata.length];
        Filter lowPass = new Filter(1.0 / ndeci);
        lowPass.filter(ddata, dataOut);
        data = dataOut;
      }

      Object result = decimate(data, ndeci);
      out.PutTime(fwdData.GetTimeStart(index), fwdData.GetTimeDuration(index));
      if (antiAlias) {
        out.PutDataAsFloat64(outIndex, (double[]) result);
      } else {
        switch (fwdData.GetType(index)) {
          case ChannelMap.TYPE_FLOAT32:
            out.PutDataAsFloat32(outIndex, (float[]) result);
            break;

          case ChannelMap.TYPE_FLOAT64:
            out.PutDataAsFloat64(outIndex, (double[]) result);
            break;

          case ChannelMap.TYPE_INT16:
            out.PutDataAsInt16(outIndex, (short[]) result);
            break;

          case ChannelMap.TYPE_INT32:
            out.PutDataAsInt32(outIndex, (int[]) result);
            break;

          case ChannelMap.TYPE_INT64:
            out.PutDataAsInt64(outIndex, (long[]) result);
            break;

          case ChannelMap.TYPE_INT8:
            out.PutDataAsInt8(outIndex, (byte[]) result);
            break;
        }
      }
    }
  }