Beispiel #1
0
 void processChannel(WinstonUtil winston, WinstonSCNL channel)
     throws SeisFileException, SQLException, DataFormatException, FileNotFoundException,
         IOException, URISyntaxException {
   List<TraceBuf2> tbList = winston.extractData(channel, params.getBegin(), params.getEnd());
   for (TraceBuf2 traceBuf2 : tbList) {
     List<DataRecord> mseedList = traceBuf2.toMiniSeed(recordSize, doSteim1);
     for (DataRecord dr : mseedList) {
       dr.write(params.getDataOutputStream());
     }
   }
 }
Beispiel #2
0
 public void readData()
     throws SeisFileException, SQLException, DataFormatException, FileNotFoundException,
         IOException, URISyntaxException {
   if (params.isPrintHelp()) {
     System.out.println(getHelp());
     return;
   } else if (params.isPrintVersion()) {
     System.out.println("Version: " + BuildVersion.getDetailedVersion());
     return;
   } else if (params.getNetwork() == null
       || params.getStation() == null
       || params.getChannel() == null) {
     System.out.println(
         BuildVersion.getDetailedVersion()
             + " one of scnl is null: n="
             + params.getNetwork()
             + " s="
             + params.getStation()
             + " l="
             + params.getLocation()
             + " c="
             + params.getChannel());
     System.out.println("LocId null is ok for scn, but needed for scnl");
     return;
   }
   if (params.isVerbose()) {
     WinstonUtil.setVerbose(true);
   }
   WinstonUtil winston =
       new WinstonUtil(
           getDbURL(), getUser(), getPassword(), winstonConfig.getProperty("winston.prefix"));
   List<WinstonSCNL> allChannels = winston.listChannelDatabases();
   Pattern staPattern =
       Pattern.compile("*".equals(params.getStation()) ? ".*" : params.getStation());
   Pattern chanPattern =
       Pattern.compile("*".equals(params.getChannel()) ? ".*" : params.getChannel());
   Pattern netPattern =
       Pattern.compile("*".equals(params.getNetwork()) ? ".*" : params.getNetwork());
   Pattern locPattern =
       Pattern.compile("*".equals(params.getLocation()) ? ".*" : params.getLocation());
   if (doSync) {
     PrintWriter out =
         new PrintWriter(new BufferedWriter(new OutputStreamWriter(params.getDataOutputStream())));
     SyncFileWriter syncOut = new SyncFileWriter("winston", out);
     for (WinstonSCNL scnl : allChannels) {
       if (staPattern.matcher(scnl.getStation()).matches()
           && chanPattern.matcher(scnl.getChannel()).matches()
           && netPattern.matcher(scnl.getNetwork()).matches()
           && locPattern.matcher(scnl.getLocId() == null ? "" : scnl.getLocId()).matches()) {
         syncChannel(winston, scnl, syncOut);
       }
     }
     syncOut.close();
   } else if (doTbZip) {
     File f = new File(params.getOutFile());
     String dirName = f.getName();
     if (dirName.endsWith(".zip")) {
       dirName = dirName.substring(0, dirName.length() - 4);
     } else {
       dirName = dirName + "_TraceBufs";
     }
     ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
     ZipEntry tbzip = new ZipEntry(dirName + "/");
     zip.putNextEntry(tbzip);
     zip.closeEntry();
     for (WinstonSCNL scnl : allChannels) {
       if (staPattern.matcher(scnl.getStation()).matches()
           && chanPattern.matcher(scnl.getChannel()).matches()
           && netPattern.matcher(scnl.getNetwork()).matches()
           && locPattern.matcher(scnl.getLocId() == null ? "" : scnl.getLocId()).matches()) {
         outputRawTraceBuf2s(winston, scnl, zip, dirName);
       }
     }
     zip.close();
   } else if (doExport) {
     EarthwormExport exporter =
         new EarthwormExport(exportPort, module, institution, "heartbeat", heartbeat);
     if (heartbeatverbose) {
       exporter.getHeartbeater().setVerbose(heartbeatverbose);
     }
     if (params.isVerbose()) {
       exporter.setVerbose(true);
       System.out.println("Waiting for client connect, port: " + exportPort);
     }
     exporter.waitForClient();
     Date startTime = params.getBegin();
     Date chunkBegin, chunkEnd;
     HashMap<WinstonSCNL, Date> lastSent = new HashMap<WinstonSCNL, Date>();
     for (WinstonSCNL scnl : allChannels) {
       if (staPattern.matcher(scnl.getStation()).matches()
           && chanPattern.matcher(scnl.getChannel()).matches()
           && netPattern.matcher(scnl.getNetwork()).matches()
           && locPattern.matcher(scnl.getLocId() == null ? "" : scnl.getLocId()).matches()) {
         lastSent.put(scnl, startTime);
       }
     }
     while (startTime.before(params.getEnd())) {
       chunkEnd = new Date(startTime.getTime() + chunkSeconds * 1000);
       for (WinstonSCNL scnl : lastSent.keySet()) {
         chunkBegin = lastSent.get(scnl);
         if (chunkBegin.before(chunkEnd)) {
           Date sentEnd = exportChannel(winston, scnl, chunkBegin, chunkEnd, exporter);
           // sendEnd is expected time of next sample, ie 1 samp period after end time of last tb
           lastSent.put(scnl, new Date(sentEnd.getTime() + 1));
         }
       }
       startTime = new Date(chunkEnd.getTime() + 1);
     }
     exporter.closeSocket();
     if (params.isVerbose()) {
       System.out.println(
           "Done sending, "
               + exporter.getNumTraceBufSent()
               + " ("
               + exporter.getNumSplitTraceBufSent()
               + " too big so split)");
     }
   } else {
     for (WinstonSCNL scnl : allChannels) {
       if (staPattern.matcher(scnl.getStation()).matches()
           && chanPattern.matcher(scnl.getChannel()).matches()
           && netPattern.matcher(scnl.getNetwork()).matches()
           && locPattern.matcher(scnl.getLocId() == null ? "" : scnl.getLocId()).matches()) {
         processChannel(winston, scnl);
       }
     }
     params.getDataOutputStream().close();
   }
   winston.close();
 }