void outputRawTraceBuf2s( WinstonUtil winston, WinstonSCNL channel, ZipOutputStream zip, String dir) throws SeisFileException, SQLException, DataFormatException, FileNotFoundException, IOException, URISyntaxException { List<TraceBuf2> tbList = winston.extractData(channel, params.getBegin(), params.getEnd()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); for (TraceBuf2 tb : tbList) { ZipEntry tbzip = new ZipEntry( dir + "/" + tb.getNetwork().trim() + "." + tb.getStation().trim() + "." + tb.getLocId().trim() + "." + tb.getChannel().trim() + "." + sdf.format(tb.getStartDate()) + ".tb"); zip.putNextEntry(tbzip); byte[] outBytes = tb.toByteArray(); zip.write(outBytes, 0, outBytes.length); zip.closeEntry(); } }
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()); } } }
void syncChannel(WinstonUtil winston, WinstonSCNL channel, SyncFileWriter syncOut) throws SeisFileException, SQLException, DataFormatException, FileNotFoundException, IOException, URISyntaxException { Calendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTime(params.getBegin()); int startYear = cal.get(Calendar.YEAR); int startMonth = cal.get(Calendar.MONTH) + 1; // why are Calendar // months zero based, // but days are one // based??? int startDay = cal.get(Calendar.DAY_OF_MONTH); cal.setTime(params.getEnd()); int endYear = cal.get(Calendar.YEAR); int endMonth = cal.get(Calendar.MONTH) + 1; // why are Calendar // months zero based, // but days are one // based??? int endDay = cal.get(Calendar.DAY_OF_MONTH); winston.writeSyncBetweenDates( channel, startYear, startMonth, startDay, endYear, endMonth, endDay, syncOut); }
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(); }