specfem::io::seismogram_writer

class seismogram_writer : public specfem::io::writer, public specfem::io::impl::ChannelGenerator

Writer for outputting seismograms at receiver locations.

Records displacement, velocity, or acceleration at receiver stations and writes time series to disk. Supports multiple output formats and wave types, with configurable sampling intervals.

Public Functions

inline seismogram_writer(const specfem::enums::seismogram::format type, const specfem::enums::elastic_wave elastic_wave, const specfem::enums::electromagnetic_wave electromagnetic_wave, const std::string output_folder, const type_real dt, const type_real t0, const int nstep_between_samples)

Construct a new seismogram writer object.

Parameters:
  • type – Format of the output file

  • output_folder – path to output folder where results will be stored

  • dt – Time interval between subsequent timesteps

  • t0 – Solver start time

  • nstep_between_samples – number of timesteps between seismogram sampling (seismogram sampling frequency)

virtual void write(specfem::assembly::assembly<specfem::dimension::type::dim2> &assembly) override

Write seismograms.

Parameters:

assembly – 2D Assembly object

virtual void write(specfem::assembly::assembly<specfem::dimension::type::dim3> &assembly) override

Write seismograms.

Parameters:

assembly – Assembly object

std::vector<std::string> get_station_filenames(const std::string &network_name, const std::string &station_name, const std::string &location_code, specfem::wavefield::type seismogram_type)

Generates SEED-compliant seismogram filenames for a given station.

Creates standardized output filenames following the SEED naming convention: <network>.<station>.<channel>.<extension> where the channel code is automatically determined based on the simulation timestep and component orientation.

For elastic media (displacement, velocity, acceleration):

  • Generates three-component seismograms with X, Y, Z components

  • TODO: Future support for other coordinate systems (NEZ, RTZ)

For acoustic media (pressure):

  • Generates single-component seismogram with P component

// Example 1: Generate velocity seismogram filenames (100 Hz, band H)
specfem::io::ChannelGenerator gen("OUTPUT_FILES", 0.01);
auto files = gen.get_station_filenames("SY", "STA01", specfem::wavefield::type::velocity);
// Returns: ["OUTPUT_FILES/SY.STA01.HXX.semv",
//           "OUTPUT_FILES/SY.STA01.HXY.semv",
//           "OUTPUT_FILES/SY.STA01.HXZ.semv"]

// Example 2: Generate pressure seismogram filename (acoustic)
auto press_files = gen.get_station_filenames("AC", "HYD01", specfem::wavefield::type::pressure);
// Returns: ["OUTPUT_FILES/AC.HYD01.HXP.semp"]

Parameters:
  • network_name – SEED network code (e.g., “II”, “IU”, “SY”)

  • station_name – SEED station code (e.g., “ANMO”, “STA01”)

  • seismogram_type – Wavefield type to output (displacement, velocity, acceleration, or pressure)

Throws:

std::runtime_error – If seismogram_type is not supported

Returns:

std::vector<std::string> Vector containing 3 filenames for elastic media or 1 for acoustic media

inline std::string get_band_code() const

Returns the SEED band code for this generator.

The band code is determined from the simulation timestep and follows FDSN conventions for broad-band instruments. Valid codes are:

  • ’L’: Long Period ( \( dt \geq 1.0 \) s, \( \approx 1 \) Hz)

  • ’M’: Mid Period ( \( 0.1 < dt < 1.0 \) s, \( > 1 \) to \( < 10 \) Hz)

  • ’B’: Broad Band ( \( 0.0125 < dt \leq 0.1 \) s, \( \geq 10 \) to \( < 80 \) Hz)

  • ’H’: High Broad Band ( \( 0.004 < dt \leq 0.0125 \) s, \( \geq 80 \) to \( < 250 \) Hz)

  • ’C’: Band C ( \( 0.001 < dt \leq 0.004 \) s, \( \geq 250 \) to \( < 1000 \) Hz)

  • ’F’: Band F ( \( dt \leq 0.001 \) s, \( \geq 1000 \) Hz)

See also

compute_band_code() for the mapping algorithm

Returns:

std::string Single-character band code

std::string get_channel_code(const char component_letter)

Generates a three-character SEED channel code for synthetic seismograms.

Constructs a SEED channel code following the format: [Band][Instrument][Orientation]

  • Band code: Determined from simulation timestep (L, M, B, H, C, or F)

  • Instrument code: ‘X’ indicating derived/synthetic data

  • Orientation code: Component direction (X, Y, Z, N, E, P, etc.)

The ‘X’ instrument code denotes “Derived or Generated Channel” per SEED standards, indicating this is synthetic data from numerical simulation rather than direct instrumental recording.

specfem::io::ChannelGenerator gen("OUTPUT_FILES", 0.05);  // dt=0.05s → Band B
std::string channel_z = gen.get_channel_code('Z');  // Returns "BXZ"
std::string channel_n = gen.get_channel_code('N');  // Returns "BXN"

Parameters:

component_letter – Single character specifying component orientation (e.g., ‘X’, ‘Y’, ‘Z’, ‘P’)

Returns:

std::string Three-character SEED channel code (e.g., “BXZ”, “HXN”, “LXP”)

std::string get_file_extension(specfem::wavefield::type seismogram_type)

Returns the file extension for a given seismogram type.

Maps wavefield types to standardized SPECFEM++ file extensions:

  • displacement → “semd”

  • velocity → “semv”

  • acceleration → “sema”

  • pressure → “semp”

Parameters:

seismogram_type – Type of wavefield output

Throws:

std::runtime_error – If seismogram_type is not supported

Returns:

std::string File extension without leading dot