⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waveform.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        Channel channel = new Channel(wfSegment.getChannelObj().getNet().trim(),
                                      wfSegment.getChannelObj().getSta().trim(),
                                      wfSegment.getChannelObj().getSeedchan().trim());  // getChannel() ??? or getSeedchan() ???
        channel.sampleRate = initSampleRate(wfSegment.getSampleInterval());
        return channel;
    }

/** Return true if time range of input data segments overlap, else false. */
    private boolean isOverlapping(DataSegment dataSegmentPrevious, DataSegment dataSegmentCurrent) {
        if ( (dataSegmentPrevious != null) && (dataSegmentCurrent != null)) {
            Date endtime = endTime(dataSegmentPrevious);
            if (endtime.after(dataSegmentCurrent.startTimestamp) &&
                        absTimeGapSeconds(dataSegmentCurrent, dataSegmentPrevious) > getEpsilon()) {
                return true;
            }
        }
        return false;
    }

/** Prints timestamps of overlapping data segments */
    private void printOverlapWarning(DataSegment dataSegmentPrevious, DataSegment dataSegment, int index) {
        System.err.println( "Warning (Waveform): overlapping time data segments:\n" + toString(index, dataSegment));
        System.err.println( "Previous  : " + dataSegmentPrevious.startTimestamp + "->" + endTime(dataSegmentPrevious) +
                                " Samples : " + dataSegment.numberOfSamples);
        System.err.println( "Current   : " + dataSegment.startTimestamp + "->" + endTime(dataSegment) +
                                " Samples : " + dataSegment.numberOfSamples );
    }

/** Return true if there's a gap greater than getEpsilon() between packets, else false. */
    private boolean hasGap(DataSegment dataSegmentPrevious, DataSegment dataSegmentCurrent) {
        if ( (dataSegmentPrevious != null) && (dataSegmentCurrent != null)) {
            Date endtime = endTime(dataSegmentPrevious);
            if (absTimeGapSeconds(dataSegmentPrevious, dataSegmentCurrent) > getEpsilon()) {
                return true;
            }
        }
        return false;
    }

/** Prints timestamps for gap between data segments */
    private void printGapWarning(DataSegment dataSegmentPrevious, DataSegment dataSegment, int index) {
        System.err.println( "Warning (Waveform): gap between time data segments:\n" + toString(index, dataSegment));
        System.err.println( "Previous  : " + dataSegmentPrevious.startTimestamp + "->" + endTime(dataSegmentPrevious) +
                                " Samples : " + dataSegment.numberOfSamples);
        System.err.println( "Current   : " + dataSegment.startTimestamp + "->" + endTime(dataSegment) +
                                " Samples : " + dataSegment.numberOfSamples );
    }

/** Converts period to sample rate.
* @exception WaveformDataException period <= 0.
*/
    private static double initSampleRate(double period) throws WaveformDataException {
        double sampleRate = -1.0;
        if (period > 0.) sampleRate = 1.0/period;
        else throw new WaveformDataException("Waveform.initSampleRate() Invalid sample rate in SEED header.");
        return sampleRate;
    }

/** Checks input against know record size type constants.
*   Known types: MINISEED_REC_512
* @exception WaveformDataException byteSize does match any known record size types.
*/
    private static int initRecordSize(int byteSize) throws WaveformDataException {
        int size = -1;
        switch (byteSize) {
            case MINISEED_REC_512:
                size = MINISEED_REC_512;
                break;
/*
            case MINISEED_REC_4096:
                size = MINISEED_REC_4096;
                break;
*/
            default:
                throw new WaveformDataException("Waveform.initRecordSize() Unsupported SEED record size: " + byteSize);
        }
        return size;
    }

/** Checks input against know format type constants.
*   Known types: MINISEED_TYPE with encoding STEIM1 as declared in the SEED documentation.
*   Returns input value if data format type is not supported.
*   @exception WaveformDataException input format type is not known.
*/
    private static int initDataFormat(int formatType) throws WaveformDataException {
        int format = -1;
        switch (formatType) {
            case MINISEED_TYPE:
                format = formatType;
                break;
            default:
                throw new WaveformDataException("Waveform.initDataFormat() Unsupported data type: " + formatType);
        }
        return format;
    }

/** Returns absolute value seconds difference between the input DataSegment object's starting times. */
    double absTimeGapSeconds(DataSegment dataSegmentLast, DataSegment dataSegmentNext) {
        return Math.abs(dataSegmentNext.getStartTimeSecs() - dataSegmentLast.getStartTimeSecs()
                         - ((double) (dataSegmentLast.numberOfSamples - 1))/chan.sampleRate );
    }

/** Returns absolute value seconds difference between the input DataCounts object's starting times. */
    double absTimeGapSeconds(DataCounts dataCountsLast, DataCounts dataCountsNext) {
        return Math.abs(dataCountsNext.getStartTimeSecs() - dataCountsLast.getStartTimeSecs()
                         - ((double) (dataCountsLast.dataList.size() - 1))/chan.sampleRate );
    }

/** Inserts the data into the input DataCounts list, appends samples to last DataCounts object in list if data is contiguous
*   else a new element is added to the list.
*/
    boolean insertCounts(List dataCountsList, DataCounts dataCountsNext) {
        int sizeofList = dataCountsList.size();
        if (sizeofList > 0) {
            DataCounts dataCountsLast = (DataCounts) dataCountsList.get(sizeofList - 1);
            double test = absTimeGapSeconds(dataCountsLast, dataCountsNext);
            if (test < getEpsilon()) {   // overlaps and gaps go to separate element
//            if (absTimeGapSeconds(dataCountsLast, dataCountsNext) < getEpsilon()) {   // overlaps and gaps go to separate element
                ArrayList dataList = (ArrayList) dataCountsLast.dataList;
                dataList.ensureCapacity(dataList.size() + Math.max(MINISEED_MIN_PACKET_SAMPLES, dataCountsNext.dataList.size()));
                boolean retVal = dataList.addAll(dataCountsNext.dataList); // append contiguous samples to last segment in list
                return retVal;
            }
       }
       return dataCountsList.add(dataCountsNext); // Append a new DataCounts element to list (a new time segment)
    }


/** Unpacks the data samples from the SEED packet data contained in the input  data segment.
*   Returns a new DataCounts object containing the the samples in an array data member.
*/
    DataCounts getSamples(DataSegment dataSegment) {
        DataCounts retVal = null;
        try {
            //int [] samples = seedReader.getDataSamples(dataSegment.dataContent);
            float [] samples = seedReader.getDataSamples(dataSegment.dataContent); // re modified D.Given's SEED reader impl
            if (samples == null) {
                System.err.println( "Error Waveform.getSamples(): No sample counts returned for input packet" );
                retVal =  null;
            }
          /*  Changed to used retrieved array rather than generating new objects
            int totalSamples = samples.length;
            List arrayList = new ArrayList(totalSamples);
            for (int index = 0; index < totalSamples; index ++) {
                //arrayList.add(new Integer(samples[index]));
                //arrayList.add(new Float(samples[index]));
                arrayList.add(samples[index]);
            }
          */
            List arrayList = new ArrayList(1);
            arrayList.add(samples); // aww to avoid object overhead shortcut ?
            retVal = new DataCounts(dataSegment.startTimestamp, arrayList);
        }
        catch(SeedReaderException ex) {
            ex.printStackTrace();
            System.err.println(ex.getMessage());
        }
        catch(Exception ex) {
            ex.printStackTrace();
            System.err.println("Waveform.getSamples(DataSegment) caught exception " + ex.getMessage());
        }
        return retVal;
    }

/** This method trims a single SEED packet to the specified time window.
*   The Time window and packet time ranges are assumed to overlap.
*   NO IMPLEMENTATION - this method always returns true.
*/
    private boolean trimPacket(DataSegment dataSegment, DataSegment dataSegmentPrevious, TimeWindow tw) {
         return true;
    }

/** Returns a miniSEED data packet Collection comprising the input waveform.
*   Supports only recordSize = MINISEED_REC_512, dataFormat = MINISEED_TYPE with data encoding STEIM1
*   Returns null if no data exist for input Waveform.
*   @exception java.lang.NullPointerException input parameter is null
*/
    public static List getMiniSEEDPackets(Waveform wave) {
        if (wave == null)
            throw new NullPointerException("Waveform.getMiniSEEDPackets null Waveform input parameter");

        if (wave.dataSegmentList == null || wave.dataSegmentList.isEmpty()) return null;

        ArrayList arrayList = new ArrayList(wave.dataSegmentList.size());

        Iterator iter = wave.dataSegmentList.iterator();
        while (iter.hasNext()) {
            arrayList.add(((DataSegment) iter.next()).dataContent);
        }
        return arrayList;
    }

/** Returns a SEED data packet Collection comprising this waveform.
*   Supports only recordSize = MINISEED_REC_512, dataFormat = MINISEED_TYPE with data encoding STEIM1
*   Returns null if no data exist for this Waveform.
*/
    List getMiniSEEDPackets() {
        if (dataSegmentList == null || dataSegmentList.isEmpty()) return null;
        ArrayList arrayList = new ArrayList(dataSegmentList.size());
        Iterator iter = dataSegmentList.iterator();
        while (iter.hasNext()) {
            arrayList.add(((DataSegment) iter.next()).dataContent);
        }
        return arrayList;
    }

/** Converts the time-series data found in the data segments of this Waveform into a list of DataCount objects.
*   DataCount objects are appended to the list specified as the input parameter.
*   Contiguous data samples are appended to the end of the DataCount object, if a time gap occurs a new DataCount object
*   is appended to the end of the list.
*   Returns false if an error occurs processing the data.
*   Returns true upon success; if no sample data exist for this waveform, no elements are appended to List.
*   @exception WaveformDataException input parameter is null.
*/
    public boolean getCounts(List dataCountsList) throws WaveformDataException {
        if (dataCountsList == null) throw new WaveformDataException("Waveform.getCounts() input List parameter is null");
        if (dataSegmentList == null || dataSegmentList.isEmpty()) return true;

        Iterator iter = dataSegmentList.iterator();
        while (iter.hasNext()) {

            DataCounts dataCounts = getSamples((DataSegment) iter.next());
            if (dataCounts == null) {
                System.err.println( "Error Waveform.getCounts(): failure getting sample counts");
                return false;
            }

            // Store the counts into the DataCount list
            if (! insertCounts(dataCountsList, dataCounts)) {
                System.err.println( "Error Waveform.getCounts(): failure inserting retrieved counts into list");
                return false;
            }
        }
        return true;
    }

/** Gets the sample rate of the time series data. if any.
*   Returns -1. if data channel is null.
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -