Exemplo 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;
    }
Exemplo n.º 2
0
    private PlugInChannelMap handleRegistration(PlugInChannelMap picm) throws Exception {
      // 	picm.PutTime( (System.currentTimeMillis()/1000.0), 0.0);

      try {
        if (((picm.GetName(0).equals("...")) || (picm.GetName(0).equals("*")))) {

          double otime = ctreader.oldTime(sourceFolder);
          double ntime = ctreader.newTime(sourceFolder);
          if (debug)
            System.err.println(
                "handleRegistration picm[0]: "
                    + picm.GetName(0)
                    + ", oldtime: "
                    + otime
                    + ", newtime: "
                    + ntime);

          picm.PutTime(otime, ntime - otime);
          if (regPicm
              != null) { // round about way to cache registration. actual RBNB pre-register does not
            // provide time limits
            if (debug) System.err.println("returning pre-fetched registration...");
            picm.Clear();
            for (int i = 0; i < regPicm.NumberOfChannels(); i++) {
              picm.Add(regPicm.GetName(i));
              picm.PutDataAsString(i, regString(regPicm.GetName(i)));
              picm.PutMime(i, "text/xml");
            }
            return picm; // return pre-fetched registration
          }

          ArrayList<String> chanlist = ctreader.listChans(sourceFolder);
          if (chanlist == null) {
            throw (new Exception("Oops, no channels for sourceFolder: " + sourceFolder));
          }
          picm.Clear();
          for (int i = 0; i < chanlist.size(); i++) {
            int j = picm.Add(chanlist.get(i));
            if (debug) System.err.println("register[" + j + "]: " + picm.GetName(j));
            picm.PutDataAsString(i, regString(chanlist.get(i)));
            picm.PutMime(i, "text/xml");
          }
        } else {
          CTmap ctmap = PI2CTmap(picm); // ignore time limits registration request
          double otime = ctreader.oldTime(sourceFolder, ctmap);
          double ntime = ctreader.newTime(sourceFolder, ctmap);
          picm.PutTime(otime, ntime - otime);
          if (debug)
            System.err.println(
                "handleRegistration picm[0]: "
                    + picm.GetName(0)
                    + ", oldtime: "
                    + otime
                    + ", newtime: "
                    + ntime);

          int nchan = picm.NumberOfChannels();
          if (debug)
            System.err.println("reg-request channel: " + picm.GetName(0) + ", num: " + nchan);
          for (int i = 0; i < nchan; i++) { // put start/end time for each channel individually?
            picm.PutDataAsString(i, regString(picm.GetName(i)));
            picm.PutMime(i, "text/xml");
          }
        }
      } catch (Exception e) {
        System.err.println("handleRegistration exception: " + e);
        e.printStackTrace();
      }
      //	 plugin.Flush(picm);
      return (picm);
    }