crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
28 stars 20 forks source link

Earthworm wave server #24

Closed andreabono closed 3 years ago

andreabono commented 3 years ago

Is there a way to post a POST request to the earthworm wave server?
If not, is there any way to post concurrent requests?

crotwell commented 3 years ago

waveserver is raw socket based, not http, so not quite sure what you mean by POST. The commands allowed are documented here; http://folkworm.ceri.memphis.edu/ew-doc/ovr/wave_serverV_ovr.html

It may be possible to send the next command before the previous one's data arrives, but I did not code seisFile's waveserver code to handle that case. The code is not complicated, so you might be able to modify it to handle that case.

That said, there is nothing prohibiting a client from opening multiple sockets for concurrent downloads. You would likely want to be multithreaded for that to be effective.

andreabono commented 3 years ago

Good, perfect... I'm migrating from version 1.8.5 to version 2.0.2 and I can't find any implementation of MSeedQueryClient.
It is not needed anymore? I can just use the WaveServer class to read data streams to miniseed files?

crotwell commented 3 years ago

Yes, you should be able to use

public List<DataRecord> read(String query)

in WaveServer to get miniseed records converted from TraceBuf2 returned from a waveserver.

andreabono commented 3 years ago

I got it, here's a working code snippet

public String  readData(String station , String channel,  String network, 
            String location, Date begin, Date end, String output_path) throws IOException{

        String outputFile = output_path +station+"."+channel+".mseed";

        try {
            // "query" is a class scoped member (String)
            query = reader.createQuery(network, station, location, channel, begin.toInstant(), end.toInstant());

            List<DataRecord> dati = reader.read(query);
            if (dati!=null){
                ListIterator drIter = dati.listIterator();

                DataOutputStream out = null;

                if (!drIter.hasNext()) {
                    System.out.println("No data for " + query);
                }

                if (outputFile != null) {
                    out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
                }
                DataRecord dr;
                while (drIter.hasNext()) {
                    dr = (DataRecord)drIter.next();

                    dr.write(out);
                }
                dr=null;

                return outputFile;
            } else 
                return null;

        } catch (Exception ex) {
            Logger.getLogger("org.ingv.pickfx").log(java.util.logging.Level.SEVERE, ex.getMessage());
            return null;
        } 
    }